Main Content

Warper

Apply same geometric transformation to many images efficiently

Description

A Warper object applies a linear 2-D geometric transformation to images with a specific size. If the input images are RGB images or 3-D grayscale images, then the Warper object applies the geometric transformation to each color channel or plane independently.

Creation

Description

w = images.geotrans.Warper(tform,inputSize) creates a Warper object that applies a 2-D geometric transformation tform to images of size inputSize.

example

w = images.geotrans.Warper(tform,inputRef) specifies the coordinate system of the input images, inputRef.

w = images.geotrans.Warper(tform,inputRef,outputRef) specifies the coordinate system of the output image, outputRef. This syntax can be used to improve performance by limiting the application of the geometric transformation to a specific output region of interest.

w = images.geotrans.Warper(sourceX,sourceY) specifies the input image coordinates, sourceX and sourceY, required to perform the geometric transformation.

w = images.geotrans.Warper(___,Name=Value) also sets one or more writable properties using name-value arguments.

For example, w = images.geotrans.Warper(tform,size(im),FillValue=1) specifies a fill value of 1 for pixels outside the original image.

Input Arguments

expand all

Geometric transformation, specified as one of these geometric transformation objects.

Geometric Transformation ObjectDescription
transltform2dTranslation transformation
rigidtform2dRigid transformation: translation and rotation
simtform2dSimilarity transformation: translation, rotation, and isotropic scaling
affinetform2dAffine transformation: translation, rotation, anisotropic scaling, reflection, and shearing
projtform2dProjective transformation

Size of the input images, specified as a 2- or 3-element vector of positive integers.

This argument sets the InputSize property.

Referencing object associated with the input image, specified as an imref2d spatial referencing object.

Referencing object associated with the output image, specified as an imref2d spatial referencing object.

Input image coordinates, specified as a 2-D matrix the same size as the required output image. Each (x, y) index in sourceX and sourceY specifies the location in the input image for the corresponding output pixel.

Data Types: single

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: w = images.geotrans.Warper(tform,size(im),FillValue=1) specifies a fill value of 1 for pixels outside the original image.

Interpolation method, specified as "linear", "nearest", or "cubic".

This argument sets the Interpolation property.

Data Types: char | string

Value used for output pixels outside the input image boundaries, specified as a numeric scalar. Warper casts the fill value to the data type of the input image.

This argument sets the FillValue property.

Properties

expand all

Size of the input images, specified as a 2- or 3-element vector of positive integers.

Size of the first two dimensions of the output image, specified as a 2-element vector of positive integers.

Interpolation method, specified as "linear", "nearest", or "cubic".

Data Types: char | string

Value used for output pixels outside the input image boundaries, specified as a numeric scalar. Warper casts the fill value to the data type of the input image.

Object Functions

warpApply geometric transformation of Warper object

Examples

collapse all

Pick a set of images of the same size. The example uses a set of images that show cells.

imds = imageDatastore(fullfile(matlabroot,"toolbox","images","imdata","AT*"));

Create a similarity geometric transformation that rotates each image by 45 degrees and shrinks each image. The transformation does not translate the images.

scaleFactor = 0.5;
theta = 45;
translation = [0 0];
tform = simtform2d(scaleFactor,theta,translation);

Create a Warper object, specifying the geometric transformation object, tform, and the size of the input images.

im = readimage(imds,1);
warper = images.geotrans.Warper(tform,size(im));

Determine the number of images to be processed and preallocate the output array.

numFiles = numel(imds.Files);
imr = zeros([warper.OutputSize 1 numFiles],"like",im);

Apply the geometric transformation to each of the input images by calling the warp function of the Warper object.

for ind = 1:numFiles
    im = read(imds);
    imr(:,:,1,ind) = warp(warper,im);
end

Visualize the output images in a montage.

montage(imr)

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

Algorithms

Warper is optimized to apply the same geometric transformation across a batch of same size images. Warper achieves this optimization by splitting the warping process into two steps: computation of the transformed coordinates (done once) and interpolation on the image (done for each image). Compared to imwarp, this approach speeds up the whole process significantly for small to medium-sized images, with diminishing returns for larger images.

Version History

Introduced in R2017b

expand all