%% Read Data in CombinedDatastore
% Create a datastore that maintains parity between the pair of images of the underlying datastores. For instance, create two separate image datastores, and then create a combined datastore that reads corresponding images from the two image datastores.
% Create an image datastore imds1 representing a collection of three images.

imds1 = imageDatastore({'peppers.png','street1.jpg','street2.jpg'}); 

% Create a second datastore imds2 containing a mask of the bright regions of the three images. To create this datastore, first transform the images of imds1 to grayscale. Then convert each image to a binary mask by performing thresholding. In this example, the thresholding operation maps pixels with a value above the threshold (250) to white and all other pixels to black.

imds2 = transform(imds1,@(x) im2gray(x)>250);

% Create a combined datastore from imds1 and imds2.

imdsCombined = combine(imds1,imds2);

%
% Read the first subset of data from the combined datastore. The output is a 1-by-2 cell array. The two columns represent the first subset of data read from the two underlying datastores imds1 and imds2, respectively.

dataOut = read(imdsCombined)

% Display the read data from the combined datastore as a pair of tiled images.

tile = imtile(dataOut);
imshow(tile)

%
% Read from the combined datastore again. This call to the read function continues reading from the endpoint of the previous call.

dataOut = read(imdsCombined)

%  Display the read data.

tile = imtile(dataOut);
imshow(tile)

% Copyright 2018 The MathWorks, Inc.