Main Content

warp

Apply geometric transformation of Warper object

Description

B = warp(w,A) applies the geometrical transformation defined by image warper w to input image A and returns the warped image in B.

If the input image is an RGB image or 3-D grayscale image, then warp applies the transformation to each color channel or plane independently.

example

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.

Input Arguments

collapse all

Image warper, specified as a Warper object.

Input image, specified as a numeric matrix with size m-by-n or m-by-n-by-p. The size of A must match w.InputSize.

Data Types: single | int16 | uint8

Output Arguments

collapse all

Transformed image, returned as a numeric matrix or numeric array. B has the same data type as A and its first two dimensions are w.OutputSize. If A has p planes, then B will also have p planes.

Version History

Introduced in R2017b

See Also

|