Color and brightness in imread

조회 수: 11 (최근 30일)
Nahyun Kim
Nahyun Kim 2019년 7월 15일
편집: KALYAN ACHARJYA 2019년 7월 15일
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
Adam
Adam 2019년 7월 15일
Stephen23
Stephen23 2019년 7월 15일
편집: Stephen23 2019년 7월 15일
"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.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2019년 7월 15일
편집: Stephen23 2019년 7월 15일
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
Nahyun Kim
Nahyun Kim 2019년 7월 15일
편집: Nahyun Kim 2019년 7월 15일
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 2019년 7월 15일
편집: KALYAN ACHARJYA 2019년 7월 15일
Thank you @Stephen for pointing my mis-conception.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by