MATLAB: Return value of rgb2gray Image Processing Toolboxmatricesmatrixreturn valuergb2gray Hi, For a given image, does rgb2gray return a mxnx3 matrix or mxn when it eliminates hue and saturation? The documentation is not clear on this. Thanks Best Answer It returns an MxN numeric array. Related SolutionsMATLAB: Rgb2gray error Convert to gray scale:Filelist= dir('Clipboard*.png');numberOfFiles = length(Filelist);for k = 1 : numberOfFiles % Don't use i (the imaginary variable). thisImage = imread(Filelist(k).name); [rows, columns, numberOfColorChannels] = size(thisImage); if k == 1 % Instantiate I with the size of the first image. I = zeros(rows, columns, numberOfFiles, class(thisImage)); end if numberOfColorChannels > 1 % It's color. Need to convert to gray scale before putting it into the 3D image as the k'th slice. I(:,:, k) = rgb2gray(thisImage); else % Already grayscale. No need to convert. Just put in directly as the k'th slice. I(:,:, k) = thisImage; endend MATLAB: Color array to grayscale, images % Read the imageimg1 = imread('photo1.jpg');% Convert it to doubleimg1Double = im2double(img1);% Convert from RGB to grayscaleimg1Gray = rgb2gray(img1);% Display the resultsfigureimshowpair(img1, img1Gray, 'montage')You can do the same for 'photo2.jpg' Related QuestionError using rgb2grayError using rgb2grayImage Analysis – Adding ImagesError while using rgb2gray
Best Answer