MATLAB: Need a grayscale non-indexed image

grayscaleImage Processing Toolboxind2graynon-indexedrgb2gray

Hi all!
I'm trying to convert some images to gray scale.
I first used rgb2gray(); But while checking results using info=iminfo(image_name) I found that info.ColorType='indexed'
So I tried I=ind2gray(image_name,map) where map was obtained from info.Colormap but I got I=0
My guess is that I put the wrong colormap. What is the right one to put???
In general, how do I get a grayscale non-indexed image????
Thanks!!!! Ilaria

Best Answer

rgb2gray and ind2gray work on an image in memory. They will both convert an image to greyscale exactly as you want.
imfinfo (I assume that's what you meant, there's no iminfo) works on an image on disk. You haven't shown us the step where you saved the image. This is probably where you've gone wrong. Most likely you've chosen an image format that do not support greyscale images. BMP for example can only store colour or indexed images so a greyscale image would have to be converted to one of these. Similarly, GIF only store images as indexed.
A format that can store greyscale (and coloured and indexed) images is PNG.