MATLAB Answers

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

11 views (last 30 days)
shawin on 16 Nov 2018
Commented: Walter Roberson on 16 Nov 2018
Iam trying to read and convert color images to gray,
The code is :
the images are BMP and they were jpg images and i convert them to BMP using online converter.
any help please ?


Walter Roberson
Walter Roberson on 16 Nov 2018
what shows up with imfinfo(im)
I suspect that it is not an indexed image , that the colormap is empty .
shawin on 16 Nov 2018
imfinfo(im) is
Error using imfinfo (line 100)
Unable to open file "face6.bmp" for reading.
i attched the face6 file !!!

Sign in to comment.

Accepted Answer

Jan on 16 Nov 2018
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.
if isempty(MAP)
gray = rgb2gray(X);
gray = ind2gray(X,MAP);

  1 Comment

Walter Roberson
Walter Roberson on 16 Nov 2018
>> imfinfo('face6.bmp')
ans =
struct with fields:
Filename: '/Users/roberson/MATLAB/4/430/430201/face6.bmp'
FileModDate: '16-Nov-2018 13:33:33'
FileSize: 108138
Format: 'bmp'
FormatVersion: 'Version 5 (Microsoft Windows 2000)'
Width: 180
Height: 200
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: 'BM'
NumColormapEntries: 0
Colormap: []
Notice "truecolor" and notice that Colormap is empty. It is not an indexed image.

Sign in to comment.

More Answers (0)