%% Read Images from S3 Bucket in Background
% This example shows how to read images from an Amazon® S3 bucket in the background.
%
% Use an image datastore to connect to your bucket. For more information on how to set up access to your S3 bucket, see Work with Remote Data.
% Replace "s3://MyBucket/data" with a URL to a data folder in your S3 bucket.

ds = imageDatastore("s3://MyBucket/data");

%
% Use parfeval to read data from the S3 bucket. Specify backgroundPool as the first argument to run the function in the background. Then, read all of the data from the datastore.

f = parfeval(backgroundPool,@readall,1,ds);

%
% You can run other functions while you download the data from the S3 bucket. To retrieve all of the images from the background, use fetchOutputs. MATLAB returns the output once the execution of readall is complete.

T = fetchOutputs(f);
imout = imtile(T);
imshow(imout)

% Copyright 2021 The MathWorks, Inc.