TransformedDatastore

Datastore to transform underlying datastore

Description

Use a TransformedDatastore object to transform, or process, data read from an underlying datastore.

Creation

You can create a TransformedDatastore object using the transform function. For example, dsnew = transform(ds,@fcn) creates a datastore that transforms datastore ds using the transformation function fcn.

Properties

expand all

Underlying datastore, specified as a datastore object.

Set of transformation functions, specified as a cell array of function handles.

Data Types: cell

Include information from read function, specified as a logical vector. For each value of IncludeInfo that is true, the transformed datastore uses the alternative signature of the corresponding transform function in transformSet.

The read function returns information about the extracted data in an info struct. For more information, see the read function page.

Data Types: logical

This property is read-only.

List of formats supported for writing, returned as a row vector of strings. This property specifies the possible output formats when using writeall to write output files from the datastore.

Data Types: string

Object Functions

combineCombine data from multiple datastores
hasdataDetermine if data is available to read
previewSubset of data in datastore
readRead data in datastore
readallRead all data in datastore
writeallWrite datastore to files
resetReset datastore to initial state
transformTransform datastore
numpartitionsNumber of datastore partitions
partitionPartition a datastore
shuffleShuffle files in datastore
isPartitionableDetermine whether datastore is partitionable
isShuffleableDetermine whether datastore is shuffleable

Examples

collapse all

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'})
imds = 
  ImageDatastore with properties:

                       Files: {
                              ' .../devel/bat/BR2020ad/build/matlab/toolbox/matlab/demos/street1.jpg';
                              ' .../devel/bat/BR2020ad/build/matlab/toolbox/matlab/imagesci/peppers.png'
                              }
                     Folders: {
                              '/mathworks/devel/bat/BR2020ad/build/matlab/toolbox/matlab/demos';
                              '/mathworks/devel/bat/BR2020ad/build/matlab/toolbox/matlab/imagesci'
                              }
    AlternateFileSystemRoots: {}
                    ReadSize: 1
                      Labels: {}
      SupportedOutputFormats: ["png"    "jpg"    "jpeg"    "tif"    "tiff"]
         DefaultOutputFormat: "png"
                     ReadFcn: @readDatastoreImage

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
  Name        Size                Bytes  Class    Attributes

  img1      480x640x3            921600  uint8              
  img2      384x512x3            589824  uint8              

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
  Name            Size                Bytes  Class    Attributes

  imgReSz1      224x224x3            150528  uint8              
  imgReSz2      224x224x3            150528  uint8              

Display the resized images.

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

Introduced in R2019a