Main Content

readByIndex

Read data specified by index from augmentedImageDatastore

Description

data = readByIndex(auimds,ind) returns a subset of observations from an augmented image datastore, auimds. The desired observations are specified by indices, ind.

example

[data,info] = readByIndex(auimds,ind) also returns information about the observations, including metadata, in info.

Examples

collapse all

Load the sample data, which consists of synthetic images of handwritten digits. XTrain is a 28-by-28-by-1-by-5000 array, where:

  • 28 is the height and width of the images.

  • 1 is the number of channels.

  • 5000 is the number of synthetic images of handwritten digits.

load DigitsDataTrain

Create an imageDataAugmenter object that specifies preprocessing options for image augmentation, such as resizing, rotation, translation, and reflection. Randomly translate the images up to three pixels horizontally and vertically, and rotate the images with an angle up to 20 degrees.

imageAugmenter = imageDataAugmenter( ...
    RandRotation=[-20,20], ...
    RandXTranslation=[-3 3], ...
    RandYTranslation=[-3 3]);

Create an augmentedImageDatastore using the image data augmented. When you read from the datastore, for example during network training using the trainnet function, the datastore performs image augmentation and resizes the images. The datastore augments the images without saving any images to memory.

imageSize = [64 64 1];
augimds = augmentedImageDatastore(imageSize,XTrain,labelsTrain,DataAugmentation=imageAugmenter);

Read from the last nine images from the datastore.

numObservations = augimds.NumObservations;
imagesToRead = numObservations-8:numObservations
imagesToRead = 1×9

        4992        4993        4994        4995        4996        4997        4998        4999        5000

minibatch = readByIndex(augimds,imagesToRead)
minibatch=9×2 table
        input         response
    ______________    ________

    {64×64 single}       2    
    {64×64 single}       3    
    {64×64 single}       9    
    {64×64 single}       9    
    {64×64 single}       8    
    {64×64 single}       9    
    {64×64 single}       8    
    {64×64 single}       9    
    {64×64 single}       3    

Show the augmented images.

imshow(imtile(minibatch.input));

Figure contains an axes object. The hidden axes object contains an object of type image.

Input Arguments

collapse all

Augmented image datastore, specified as an augmentedImageDatastore object.

Indices of observations, specified as a vector of positive integers.

Output Arguments

collapse all

Observations from the datastore, returned as a table with length(ind) number of rows.

Information about read data, returned as a structure array with the following fields.

Field NameDescription
MiniBatchIndicesNumeric vector of indices.

Version History

Introduced in R2018a