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?
0 个评论
采纳的回答
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)
imshow(inpict,'border','tight')
See also:
2 个评论
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)
unique(A)
% 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)
unique(A)
If the image type or classes vary within a directory, I see no way to handle that.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!