Color and brightness in imread

11 visualizzazioni (ultimi 30 giorni)
Nahyun Kim
Nahyun Kim il 15 Lug 2019
Modificato: KALYAN ACHARJYA il 15 Lug 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 Commenti
Adam
Adam il 15 Lug 2019
doc imwrite
Stephen23
Stephen23 il 15 Lug 2019
Modificato: Stephen23 il 15 Lug 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.

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 15 Lug 2019
Modificato: Stephen23 il 15 Lug 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 Commenti
Nahyun Kim
Nahyun Kim il 15 Lug 2019
Modificato: Nahyun Kim il 15 Lug 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 il 15 Lug 2019
Modificato: KALYAN ACHARJYA il 15 Lug 2019
Thank you @Stephen for pointing my mis-conception.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by