why I use imread fuction this photo not RGB array?

4 ビュー (過去 30 日間)
Latch Wu
Latch Wu 2023 年 9 月 18 日
編集済み: DGM 2023 年 9 月 19 日
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 件)

タグ


Translated by