You can use imfinfo to get information about the image file before downloading it:
info = imfinfo('sample_image.jpg'); info.ColorType % eg 'grayscale', 'truecolor', 'indexed' info.BitDepth % eg 8, 16
You can also look at the imread help topic to find out which output class will be used for different file types. The problem is to determine the difference between the grayscale image and the indexed color file - they will have the same size and class. In this case, you need to check ColorType and load the color map when viewing the image:
[I, map] = imread(filename)
source share