why I use imread fuction this photo not RGB array?

12 views (last 30 days)
temp = imread('image.png');
% temp = 3000x4000 uint8?
why this photo don't have RGB 3D-array?
because I use pixelLabelDatastore function. then show result
Pixel label image must have 3 channels when RGB-triplet pixel label IDs are specified.
L = matlab.io.datastore.PixelLabelDatastore.label2cat(...
C = this.label2categorical(C, info);
It let me check the photo, why don't have rgb 3d array?

Accepted Answer

DGM
DGM on 18 Sep 2023
It's an indexed-color image. If you want it to be RGB, you can convert it.
% this is an indexed image and its corresponding color table
[inpict map] = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1485727/image.png');
% convert it to RGB
inpict = ind2rgb(inpict,map);
size(inpict)
ans = 1×3
3000 4000 3
imshow(inpict,'border','tight')
See also:
  2 Comments
Latch Wu
Latch Wu on 18 Sep 2023
DGM, thanks your reply,
I has trouble in this code
pxds = pixelLabelDatastore(labelDir,classes,labelIDs);
C = readimage(pxds,1);
when I have many indexed-color image[s] in labelDir.
how to use pixelLabelDatastore function,
whether every indexed-color image file that must be transfer to RGB struction, then run function "pixelLabelDatastore" ?
DGM
DGM on 19 Sep 2023
Edited: DGM on 19 Sep 2023
I don't have CVT, so I'm not familiar with pixelLabelDatastore, but I think the way labelIDs are specified depends on the type of each image.
If it's an RGB image, they're specified as a color table, but if the file is indexed color, the labels are specified as the index.
% do it with an RGB input
classes = {'a','b','c','d','e','f'};
labelIDs = [0 0 0; 102 102 156; 128 64 128; 107 142 35; 0 0 142; 70 70 70];
pxds = pixelLabelDatastore('./',classes,labelIDs);
A = readimage(pxds,2);
size(A)
ans = 1×2
3000 4000
unique(A)
ans = 6×1 categorical array
a b c d e f
% do it with an indexed input
classes = {'a','b','c','d','e','f'};
labelIDs = 0:5;
pxds = pixelLabelDatastore('./',classes,labelIDs);
A = readimage(pxds,1);
size(A)
ans = 1×2
3000 4000
unique(A)
ans = 6×1 categorical array
a b c d e f
If the image type or classes vary within a directory, I see no way to handle that.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!