How to write imageDatastore include labels.

4 次查看(过去 30 天)
Hi all..
I have the original data (ImageTr as attached), and labels data (LabelsTr as attached) for training. My problems is how to write imageDatastore include labels in it?
Because the labels in LabelsTr folder
I try this one but was error.
clc
clear all
close all
%testDataimages
DATASetDir = fullfile('C:\Users\Akmal\Desktop\NEW 3D U NET');
IMAGEDir = fullfile(DATASetDir,'ImagesTr');
volReader = @(x) matRead(x);
volds = imageDatastore(IMAGEDir, ...
'FileExtensions','.mat','ReadFcn', volReader);
% labelReader = @(x) matread(x);
matFileDir = fullfile('C:\Users\Akmal\Desktop\NEW 3D U NET\LabelsTr');
classNames = ["background", "tumor"];
pixelLabelID = [0 1];
% pxds = (LabelDirr,classNames,pixelLabelID, ...
% 'FileExtensions','.mat','ReadFcn',labelReader);
pxds = pixelLabelDatastore(matFileDir,classNames,pixelLabelID, ...
'FileExtensions','.mat','ReadFcn',@matRead);
p = imageDatastore(volds,pxds);
ERROR
Error using imageDatastore
Expected a string scalar or character vector for the parameter name.

采纳的回答

David Ho
David Ho 2022-8-24
To combine the two datastores into a single datastore, one option would be to use the combine function to create a CombinedDatastore:
cds = combine(volds, pxds);
Alternatively, if you wish to use the datastore for semantic segmentation, you might find a randomPatchExtractionDatastore to be the most useful:
patchSize = [50 50 50];
patchds = randomPatchExtractionDatastore(volds, pxds, patchSize);
This extracts corresponding randomly-positioned patches from the two datastores.
For a complete example showing how to perform semantic segmentation of 3-D volumes using deep learning, you can take a look at this example:

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by