How to convert RGB images to grayscale in matlab without using rgb2gray -
i'm using code:
i = imread('/usr/share/icons/matlab.png'); k=1:1:m l=1:1:n %a(k,l)=m*n; a(k,l) = (.299*i(k,l,1))+(.587*i(k,l,2))+(.114*i(k,l,3)); end end imshow(a); it shows white screen. newly generated dimensions n x m x 3 whereas should m x n x 1.
if use mat2gray display image this

since image png, imread() returning integer image, intensity values in range [0 255] or equivalent, depending on original bit depth. conversion formula makes a double image, expected have intensities in range [0 1]. since pixel values in a greater 1, clipped 1 (white) imshow().
the best option explicitly convert image format before start - take care of scaling things correctly:
i = imread('/usr/share/icons/matlab.png'); = im2double(i); = .299*i(:,:,1) + .587*i(:,:,2) + .114*i(:,:,3); % no need loops imshow(a);
Comments
Post a Comment