pixelLabelDatastore only supports pixel label image files with uint8 data

5 次查看(过去 30 天)
I have built a Segnet (deep learning network) for tumor segmentation. My images are stored in 3D form with extension (.nii) i.e. medical file named NIFTI (Neuro imaging) file. each .nii file contains varying no of slices from 40 to 1200.
Can you please help me to clear this error?
Error using trainNetwork (line 165)
By default, pixelLabelDatastore only supports pixel label image files with uint8 data.
Use ReadFcn to specify a custom read function that returns categorical labels from non-uint8 image data.
  4 个评论
Walter Roberson
Walter Roberson 2022-7-3
Which of the three possibilities I described matches for you? https://www.mathworks.com/matlabcentral/answers/490601-pixellabeldatastore-only-supports-pixel-label-image-files-with-uint8-data#answer_408483

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2020-1-3
There are three possibilities in this situation:
1)
If the image input file happens to not be uint8, but there are at most 256 different unique input values and each of them represents a different class, then construct a mapping list of the expected unique input values:
value_list = [17, 83:89, 293:295]; %the unique values that occur
Then have a custom ReadFcn that does:
InputImage = imread(filename);
[~, idx] = ismember(InputImage, value_list);
LabelOutput = uint8(idx-1);
2)
If the image input file happens to not be uint8, and there are more than 256 different unique input values, but multiple input values correspond to the same class, so there are at most 256 different classes, then construct a two-part mapping list:
value_list = [17, 83 84 84 86 87 88 89, 293 294 295]; %the unique values that occur
classnums = [1, 2 2 2 3 4 4 4, 5 6 6]; %corresponding class numbers
and have a custom ReadFcn that does
InputImage = imread(filename);
[~, idx] = ismember(InputImage, value_list);
LabelOutput = uint8(classnums(idx));
3)
If the image input file happens to not be uint8, and there are more than 256 different classes, then use the technique shown in https://www.mathworks.com/help/matlab/ref/categorical.html#bt0w4ft-4 "Specify category names for integers" to construct a categorical array corresponding to the inputs. If you want multiple input values to correspond to the same category then you can list the same category name multiple times. For example,
>> A = categorical(1:10, [1;2;3;4;10],{'one', 'two', 'three', 'three', 'three'}), uint16(A)
A =
1×10 categorical array
one two three three <undefined> <undefined> <undefined> <undefined> <undefined> three
ans =
1×10 uint16 row vector
1 2 3 3 0 0 0 0 0 3

Gökay Karayegen
Gökay Karayegen 2020-5-24
Hello how can I fix the following error. Please help me to solve this problem ?
classNames = ["background","edema","nonEnhancingTumor","enhancingTumour"];
labelIDs = [0 1 2 3];
dinfo = dir(fullfile(labelDir, '**', '*.nii'));
filenames = fullfile({dinfo.folder}, {dinfo.name});
pxds = pixelLabelDatastore(filenames,classNames,labelIDs);
pxds.ReadFcn = matReader;
ERROR
.bmp,.cur,.fts,.fits,.gif,.hdf,.ico,.j2c,.j2k,.jp2,.jpf,.jpx,.jpg,.jpeg,.pbm,.pcx,.pgm,.png,.pnm,.ppm,.ras,.tif,.tiff,.xwd
Error in pixelLabelDatastore (line 152)
ds = matlab.io.datastore.PixelLabelDatastore.create(location, classes, values, params);
Error in semantik_derinogrenme (line 118)
pxds = pixelLabelDatastore(filenames,classNames,labelIDs);
  1 个评论
Walter Roberson
Walter Roberson 2020-5-24
编辑:Walter Roberson 2020-5-24
You seem to have left out the first line or two of the error message? Was it saying that only the given file types were accepted?
Ah, I see you posted the whole message over at https://www.mathworks.com/matlabcentral/answers/488024-input-folders-or-files-do-not-contain-specified-file-extensions#comment_849845 which is probably a better place to have the conversation.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by