I have trained 80% of a data image, but want to Rotate and Crop only 10%. How to rotate and crop only the 10% and show cropped image

2 views (last 30 days)
clear ;
clc;
imds = imageDatastore('D:\dataimage','IncludeSubfolders',true,'LabelSource','foldernames');
[imdsTrain,imdsValidation,imdsTest] = splitEachLabel(imds,0.8,0.1,0.1);
augimdsTrain = augmentedImageDatastore([227 227],imdsTrain);
augimdsValidation = augmentedImageDatastore([227 227],imdsValidation); % resize image
augimdsTest = augmentedImageDatastore([227 227],imdsTest);
g=ceil((t1.Count*10/100));

Answers (1)

Prateek Rai
Prateek Rai on 13 Sep 2021
To my understanding, you have trained 80% of a data image, but want to Rotate and Crop only 10%.
For cropping,you can use ''OutputSizeMode' Name-value pair of 'augmentedImageDatastore' and set it to 'centercrop' or 'randcrop' as per your requirement.
augimdsValidation = augmentedImageDatastore([227 227],imdsValidation,'OutputSizeMode','centercrop');
For rotation, you can use 'imageDataAugmenter' in 'augmentedImageDatastore'. 'imageDataAugmenter' will use 'RandRotation' to set range of rotation.
% imageDataAugmenter use 'RandRotation' to set range of rotation.
augmenter = imageDataAugmenter('RandRotation',[0 360]);
% 'imageDataAugmenter' will passed to 'augmentedImageDatastore' as 'DataAugmentation' Name-Value pair
augimdsValidation = augmentedImageDatastore([227 227],imdsValidation,'DataAugmentation',augmenter);
You can club both to get crop and rotation both:
augmenter = imageDataAugmenter('RandRotation',[0 360]);
augimdsValidation = augmentedImageDatastore([227 227],imdsValidation,'OutputSizeMode','centercrop','DataAugmentation',augmenter);
You can refer to augmentedImageDatastore MathWorks documentation page to find more on augmentedImageDatastore and imageDataAugmenter MathWorks documentation page to find more on imageDataAugmenter.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!