Color and brightness in imread

4 Ansichten (letzte 30 Tage)
Nahyun Kim
Nahyun Kim am 15 Jul. 2019
Bearbeitet: KALYAN ACHARJYA am 15 Jul. 2019
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?
rgbtest.png
  4 Kommentare
Adam
Adam am 15 Jul. 2019
doc imwrite
Stephen23
Stephen23 am 15 Jul. 2019
Bearbeitet: Stephen23 am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 15 Jul. 2019
Bearbeitet: Stephen23 am 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)
If you really want to convert it to an RGB image, then that is also trivial with ind2rgb:
>> rgb = ind2rgb(im,map);
The MATLAB documentation has a very good explanation of different image types (e.g. indexed, RGB, grayscale):
  2 Kommentare
Nahyun Kim
Nahyun Kim am 15 Jul. 2019
Bearbeitet: Nahyun Kim am 15 Jul. 2019
Thank you for your help. We've implemented your solution into our code but now it is giving us this error within the ind2rgb module:
Error in ind2rgb (line 26)
r = zeros(size(a)); r(:) = cm(a,1);
EDIT: we've solved this problem, but now we have another: we need to combine the image with a binary mask, but the images are of different formats. What kind of image is outputted by createMask and how do we make it compatible with the kind of image we have now (we have started to use LAB)?
KALYAN ACHARJYA
KALYAN ACHARJYA am 15 Jul. 2019
Bearbeitet: KALYAN ACHARJYA am 15 Jul. 2019
Thank you @Stephen for pointing my mis-conception.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by