Is there a way to visualize augmented image data created by imageDataAugmenter()?

5 views (last 30 days)
I would like to confirm a few images just to understand what imageDataAugmenter does. Is there a way to visualize the augmented image data created by the imageDataAugmenter?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Aug 2021
Edited: MathWorks Support Team on 23 Aug 2021
For R2018a.
In R2018a, the  ‘augmentedImageSource’ has been replaced by ‘augmentedImageDatastore’ and the ‘preview’ method can be used to preview the data as follows:
augimds = augmentedImageDatastore()
ims = augimds.preview();
montage(ims{1:6,1}) % to visualize 6 images
'preview' does not reset the datastore.
In alternative, the method ‘read’ can be used to view the next batch of data as shown below:
augimds = augmentedImageDatastore();
numBatches = ceil(augimds.NumObservations / augimds.MiniBatchSize);
for i = 1:numBatches
    ims = augimds.read();
    montage(ims{:,1});
    pause;
end
augimds.reset();
For R2017b:
The built-in functionality to do this is not  available on Neural Network Toolbox (R2017b).
1) One of the possible workarounds is to make use of augmentedImageSource's hidden methods and properties for iterating over the data. For example:
[XTrain,YTrain] = digitTrain4DArrayData;
imageAugmenter = imageDataAugmenter('RandRotation',[-180 180],'RandXReflection',true,'RandYReflection',true);
imageSize = [28 28 1];
datasource = augmentedImageSource(imageSize,XTrain,YTrain,'DataAugmentation',imageAugmenter);
datasource.MiniBatchSize = 16;
datasource.reset();
numBatches = ceil(datasource.NumberOfObservations / datasource.MiniBatchSize);
for i = 1:numBatches
ims = datasource.nextBatch();
montage( cat(4, ims) );
pause;
end
This will show a 4x4 montage of augmented data. You can cycle through all the data by pressing any key on the keybord.
2) Another workaround is to set a breakpoint on line 484 of imageDataAugmenter and then visualize variable "B" by using imshow().
3) A third way would be to create a new layer just for image visualization. This layer could be placed after the imageInputLayer and all it would do is display the input images (again using 'montage' for example) during training. ​You would only need to edit the 'predict' method with the code to display the incoming images (X).
The documentation on how to create a new deep learning layer can be found here:

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!