%% Create Image Data Augmenter to Resize and Rotate Images
% Create an image data augmenter that preprocesses images before training. This augmenter rotates images by random angles in the range [0, 360] degrees and resizes images by random scale factors in the range [0.5, 1].

augmenter = imageDataAugmenter( ...
    'RandRotation',[0 360], ...
    'RandScale',[0.5 1])

%
% Create an augmented image datastore using the image data augmenter. The augmented image datastore also requires sample data, labels, and an output image size.

[XTrain,YTrain] = digitTrain4DArrayData;
imageSize = [56 56 1];
auimds = augmentedImageDatastore(imageSize,XTrain,YTrain,'DataAugmentation',augmenter)

%
% Preview the random transformations applied to the first eight images in the image datastore.

minibatch = preview(auimds);
imshow(imtile(minibatch.input));

% Preview different random transformations applied to the same set of images.

minibatch = preview(auimds);
imshow(imtile(minibatch.input));

% Copyright 2018 The MathWorks, Inc.