read
Read data from augmentedImageDatastore
Description
Examples
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.
labelsTrain
is a categorical vector containing the labels for each observation.
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 datastore.
minibatch = read(augimds)
minibatch=128×2 table
input response
______________ ________
{64×64 single} 3
{64×64 single} 3
{64×64 single} 7
{64×64 single} 7
{64×64 single} 7
{64×64 single} 7
{64×64 single} 9
{64×64 single} 9
{64×64 single} 7
{64×64 single} 7
{64×64 single} 3
{64×64 single} 9
{64×64 single} 9
{64×64 single} 7
{64×64 single} 3
{64×64 single} 7
⋮
Show the first nine augmented images.
imshow(imtile(minibatch.input(1:9)));
Input Arguments
Augmented image datastore, specified as an augmentedImageDatastore
object. The datastore specifies a
MiniBatchSize
number of observations in each batch, and a
numObservations
total number of observations.
Output Arguments
Output data, returned as a table. When the datastore
auimds
reads a full batch of data, the table has
MiniBatchSize
rows. For the last batch of data in the
datastore, if numObservations
is not cleanly divisible by
MiniBatchSize
, then read
returns
a partial batch containing all of the remaining observations.
The first column of the table, "input"
, returns the
data for each image. The table has a second column,
"response"
, when auimds
reads
data of these types:
Image files containing labeled image data, when the file names are specified by an image datastore
A numeric array containing categorical labels or numeric responses
A table that includes one or more responses
Information about read data, returned as a structure array. The structure array can contain these fields.
Field Name | Description |
---|---|
Filename | Cell array of character vectors. Each element
is a fully resolved path containing the path string,
name of the file, and file extension for the
corresponding image. This field is present when
|
FileSize | Numeric vector. Each element is the total file
size, in bytes, of the corresponding
image. For
MAT-files, |
Label | Categorical vector. Each element is the
category label of the corresponding image. This
field is present when |
MiniBatchIndices | Numeric vector. Each element is the index of
the input image in the array. This field is present
when |
Version History
Introduced in R2018a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)