MATLAB: Function IND2GRAY expected input number 2, MAP, to be a valid colormap.

image analysisimage processing

Iam trying to read and convert color images to gray,
The code is :
[X,MAP]=imread(im);
x=ind2gray(X,MAP);
the images are BMP and they were jpg images and i convert them to BMP using online converter.
any help please ?

Best Answer

Maybe " i convert them to BMP using online converter" was a bad idea. Why don't you use the JPG files directly? Matlab can access then efficiently and is able to convert them the BMP also. Then the indirection over an "online converter" seems to be unnecessary.
"Unable to open file "face6.bmp" for reading." might mean, that you are in the wrong directoy or that the BMP file is corrupted. The image file can be opened in the browser without problems, so I assume that you can fix the input of imfinfo and provide the output.
Alternatively you can check the contents of Map by your own. Obviously it is not the required color map, so maybe it is empty, because X is an RGB image? In this case use rgb2gray instead.
[X,MAP]=imread(im);
if isempty(MAP)
gray = rgb2gray(X);
else
gray = ind2gray(X,MAP);
end