Documentation

images.geotrans.Warper

Apply same geometric transformation to many images efficiently

Description

AWarperobject creates an image warper from anaffine2dorprojective2dgeometric transformation object for images with a specific size.

Creation

Syntax

w = images.geotrans.Warper(tform,inputSize)
w = images.geotrans.Warper(tform,inputRef)
w = images.geotrans.Warper(tform,inputRef,outputRef)
w = images.geotrans.Warper(sourceX,sourceY)
w = images.geotrans.Warper(___,Name,Value)

Description

example

w = images.geotrans.Warper(tform,inputSize)creates an image warper from the geometric transformation objecttformfor images with sizeinputSize.

w = images.geotrans.Warper(tform,inputRef)creates an image warper, whereinputRefspecifies the coordinate system of the input images.

w = images.geotrans.Warper(tform,inputRef,outputRef)creates an image warper, whereoutputRefspecifies the coordinate system of the output image. 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)creates an image warper, wheresourceXandsourceYspecify the input image coordinates required to perform the geometric transformation.sourceXandsourceYare 2-D matrices of the same size as the required output image. Each (x,y) index insourceXandsourceYspecifies the location in the input image for the corresponding output pixel.

w = images.geotrans.Warper(___,Name,Value)sets properties using one or more name-value pairs, for any of the previous syntaxes. For example,warper = images.geotrans.Warper(tform,size(im),'FillValue',1)specifies the value used for pixels outside the original image. Enclose each property name in single quotes.

Input Arguments

expand all

Geometric transformation, specified as anaffine2dorprojective2dgeometric transformation object.

Input image size, specified as a 1-by-2 or 1-by-3 vector of the form[m n]or[m n p].

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32

Referencing object associated with the input image, specified as animref2dspatial referencing object.

Referencing object associated with the output image, specified as animref2dspatial referencing object.

Input image coordinates, specified as a 2-D matrix the same size as the required output image.

Data Types:single

Properties

expand all

Size of the input images, specified as a two-element vector of the form[m n]or a three-element vector of the form[m n p].

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical

Size of the first two dimensions of the output image, specified as a two-element vector of the form[m n].

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical

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.Warpercasts the fill value to the data type of the input image.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Object Functions

warp Apply geometric transformation

例子

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*'));

创建一个geometric transform to rotate each image by 45 degrees and to shrink each image.

tform = affine2d([ 0.5*cos(pi/4) sin(pi/4) 0; -sin(pi/4) 0.5*cos(pi/4) 0; 0 0 1]);

创建一个Warperobject, 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 thewarpfunction of theWarperobject.

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

Visualize the output images. (Turn off the warning message about the images being scaled for display.)

warning('off','images:initSize:adjustingMag') montage(imr);

Tips

  • If the input images havepplanes ([m,n,p]),warpapplies the transform to each plane independently.

Algorithms

Warperis optimized to apply the same geometric transformation across a batch of same size images.Warperachieves 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 toimwarp, this approach speeds up the whole process significantly for small to medium-sized images, with diminishing returns for larger images.

Introduced in R2017b

Was this topic helpful?