why I use imread fuction this photo not RGB array?

2 次查看(过去 30 天)
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?

采纳的回答

DGM
DGM 2023-9-18
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 个评论
Latch Wu
Latch Wu 2023-9-18
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 2023-9-19
编辑:DGM 2023-9-19
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Display Image 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by