augment - Apply identical random transformations to multiple images - MATLAB (original) (raw)

Main Content

Apply identical random transformations to multiple images

Syntax

Description

[augI](#mw%5Ffb22ac1e-361d-45c7-873f-9751ca7a6167) = augment([augmenter](#mw%5F3bc6f86d-e28c-4392-9fd7-725be91355f9),[I](#mw%5F17f09263-5d88-4b93-96ea-886fa67cf23c)) augments image I using a random transformation from the set of image preprocessing options defined by image data augmenter, augmenter. IfI consists of multiple images, then augment applies an identical transformation to all images.

example

Examples

collapse all

Augment Image Data with Custom Rotation Range

Create an image augmenter that rotates images by a random angle. To use a custom range of valid rotation angles, you can specify a function handle when you create the augmenter. This example specifies a function called myrange (defined at the end of the example) that selects an angle from within two disjoint intervals.

imageAugmenter = imageDataAugmenter('RandRotation',@myrange);

Read multiple images into the workspace, and display the images.

img1 = imread('peppers.png'); img2 = imread('corn.tif',2); inImg = imtile({img1,img2}); imshow(inImg)

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

Augment the images with identical augmentations. The randomly selected rotation angle is returned in a temporary variable, angle.

outCellArray = augment(imageAugmenter,{img1,img2});

View the augmented images.

outImg = imtile(outCellArray); imshow(outImg);

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

Supporting Function

This example defines the myrange function that first randomly selects one of two intervals (-10, 10) and (170, 190) with equal probability. Within the selected interval, the function returns a single random number from a uniform distribution.

function angle = myrange() if randi([0 1],1) a = -10; b = 10; else a = 170; b = 190; end angle = a + (b-a).*rand(1) end

Input Arguments

collapse all

augmenter — Augmentation options

imageDataAugmenter object

Augmentation options, specified as an imageDataAugmenter object.

I — Images to augment

numeric array | cell array of numeric and categorical images

Images to augment, specified as one of the following.

Output Arguments

collapse all

augI — Augmented images

numeric array | cell array of numeric and categorical images

Augmented images, returned as a numeric array or cell array of numeric and categorical images, consistent with the format of the input imagesI.

Tips

Version History

Introduced in R2018b