Color and brightness in imread
11 views (last 30 days)
Show older comments
While testing a program in Matlab, there kept being errors about arrays generated by imread not having 3 layers (ie, when the command was imshow(imgarray(:,:,1); the interpreter gave the error "Index exceeds matrix dimensions." I decided to test imread's capabilities with the following image, but Matlab seemed to interpret it as a 1-layer greyscale image rather than a color image with three color channels. How do I make Matlab read the image like it is in color when it defaults to black and white?
4 Comments
Stephen23
on 15 Jul 2019
Edited: Stephen23
on 15 Jul 2019
"Is there a way to specify how the file is stored or how it is imported into matlab?"
Yes, it is easy to find out how the image is stored (in an image file), and how to import it into MATLAB. See my answer. KALYAN ACHARJYA's answer is completely unrelated to your indexed image.
Accepted Answer
Stephen23
on 15 Jul 2019
Edited: Stephen23
on 15 Jul 2019
Your image is actually an indexed image, not a grayscale image, and this is easy to find out using the inbuilt imfinfo:
>> imfinfo('rgbtest.png')
ans =
Filename: 'C:\Users\stephen.cobeldick\Documents\MATLAB\working\rgbtest.png'
FileModDate: '15-Jul-2019 18:23:52'
FileSize: 3482
Format: 'png'
FormatVersion: []
Width: 800
Height: 600
BitDepth: 8
ColorType: 'indexed' % <------ LOOK HERE!
FormatSignature: [137 80 78 71 13 10 26 10]
Colormap: [256x3 double]
Histogram: []
... etc.
Indexed images are trivial to work with, once you have the corresponding colormap:
>> [im,map] = imread('rgbtest.png');
>> imshow(im,map)
>> rgb = ind2rgb(im,map);
The MATLAB documentation has a very good explanation of different image types (e.g. indexed, RGB, grayscale):
2 Comments
KALYAN ACHARJYA
on 15 Jul 2019
Edited: KALYAN ACHARJYA
on 15 Jul 2019
Thank you @Stephen for pointing my mis-conception.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!