MATLAB Answers

Augmented image datastore for color images and pixelLabel images

11 views (last 30 days)
Marina Batlló RIus
Marina Batlló RIus on 1 Mar 2021
Answered: Divya Gaddipati on 8 Mar 2021
Good morning,d
I am trying to train a U-net network with an augmented image datastore. I have my two Datastores: the first one with RGB images corresponding to the original images (imds), and the second one with the pixelLabel images (pxds). When I try to use augmentedImageDatastore, I recieve an error for the type of input that gives pxds. I imagine that it is caused because they are images and the entrance must be a vector, but I do not know how to solve it. Could you help me?
imagesize = [2000 2000 3];
imageAugmenter = imageDataAugmenter( ...
'RandXReflection', true, ...
'RandXScale',[1,2], ...
'RandYReflection', true, ...
augimds = augmentedImageDatastore(imageSize,imds,pxds,'DataAugmentation',imageAugmenter);
Error using augmentedImageDatastore/parseInputs (line 503)
Responses cannot be specified when second input argument is a
Error in augmentedImageDatastore (line 251)
inputs = self.parseInputs(varargin{:});
Appart, I have a problem when using spliteach label. I try to do it for my variable ds (which is the datastore for both imgds and pxds) and it also gives me an error:
ds = pixelLabelImageDatastore(imds,pxds);
[trainX, trainY] = splitEachLabel(ds, 0.7, 'randomized');
Check for missing argument or incorrect argument data type in call to function 'splitEachLabel'.

Answers (1)

Divya Gaddipati
Divya Gaddipati on 8 Mar 2021
When you are using datastore inputs for augmentedImageDatastore, imds and pxds cannot be provided as separate inputs to the function. There are two ways to specify the image augmentation methods:
1) You can create a pixelLabelImageDatastore object and provide that as an input.
ds = pixelLabelImageDatastore(imds,pxds);
augimds = augmentedImageDatastore(imageSize,imds,pxds,'DataAugmentation',imageAugmenter);
Please refer to the documentation page of augmentedImageDatastore where it explains the valid syntaxes.
2) You can also use the 'DataAugmentation' name-value argument to specify the image augmentor.
augpxds = pixelLabelImageDatastore(imds,pxds,'DataAugmentation',imageAugmenter);
To answer your second question, splitEachLabel works only on imageDatastore as it is described in the documentation page.
Alternatively, you can use the partitionByIndex method provided by the pixelLabelImageDatastore object to split your data.
totalImages = numel(ds.Images);
% Split 80% of the data into training and rest into validation
idx = floor(0.8 * totalImages);
% Partition the datastore according to the specified indices
pximds_train = partitionByIndex(ds, 1:idx);
pximds_val = partitionByIndex(ds, (idx + 1):totalImages);

Community Treasure Hunt

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

Start Hunting!