%% Apply Transformation to Collection of Images
% Create a datastore for a collection of images and apply the same transformation to all the images in the datastore. For instance, resize all the images in a collection to a specified target size.
% Create an ImageDatastore with two images.

imds = imageDatastore({'street1.jpg','peppers.png'})

% Read all the images. Notice that the datastore contains images of different sizes.

img1 = read(imds); % reads the first image
img2 = read(imds); % reads the next image
whos img1 img2

% Transform all the images in the datastore to a specified target size.

targetSize = [224,224];
imdsReSz = transform(imds,@(x) imresize(x,targetSize));

% Read the images and display their sizes.

imgReSz1 = read(imdsReSz);
imgReSz2 = read(imdsReSz);
whos imgReSz1 imgReSz2

% Display the resized images.

subplot(121); imshow(imgReSz1); axis on; title('Resized Street1.jpg');
subplot(122); imshow(imgReSz2); axis on; title('Resized peppers.png');

% Copyright 2018 The MathWorks, Inc.