Apply 2D spatial transformation to image
imtransform
is not recommended. Use imwarp
instead.
B = imtransform(A,tform)
B = imtransform(A,tform,interp
)
[B,xdata,ydata] = imtransform(...)
[B,xdata,ydata] = imtransform(...,Name,Value)
B = imtransform(A,tform)
transforms
the image A
according to the 2D spatial transformation
defined by tform
. If ndims(A) > 2
,
such as for an RGB image, then imtransform
applies
the same 2D transformation to all 2D planes along the higher dimensions.
B = imtransform(A,tform,
specifies
the form of interpolation to use.interp
)
[B,xdata,ydata] = imtransform(...)
returns
the location of the output image B
in the output
XY space. By default, imtransform
calculates xdata
and ydata
automatically
so that B
contains the entire transformed image A
.
However, you can override this automatic calculation by specifying
values for the 'XData'
and 'YData'
arguments.
[B,xdata,ydata] = imtransform(...,Name,Value)
transforms
the image with additional options for controlling various aspects
of the spatial transformation specified by one or more Name,Value
pair
arguments.

An image of any nonsparse numeric class (real or complex) or
of class 

A spatial transformation structure returned by 

Form of interpolation to use, specified as: Default: 
Optional commaseparated pairs of Name,Value
arguments,
where Name
is the argument name and Value
is
the corresponding value. Name
must appear within
single quotes (' '
) and is not case sensitive.
You can specify several name and value pair arguments in any order
as Name1
, Value1
, ..., NameN
, ValueN
.

A twoelement, real vector that, when combined with Default:  

A twoelement, real vector that, when combined with Default:  

A twoelement, real vector that, when combined with Default: If you do not specify  

A twoelement real vector that, when combined with Default: If you do not specify  

A one or twoelement real vector. The first element of Default: If you do not specify
 

A twoelement vector of nonnegative integers that specifies
the number of rows and columns of the output image Default: If you do not specify  

An array containing one or several fill values. The For example, if
If 

Output image of any nonsparse numeric class (real or complex)
or of class  

Twoelement vector that specifies the xcoordinates
of the first and last columns of
 

Twoelement vector that specifies the ycoordinates
of the first and last rows of 
Simple Transformation. Apply a horizontal shear to an intensity image:
I = imread('cameraman.tif'); tform = maketform('affine',[1 0 0; .5 1 0; 0 0 1]); J = imtransform(I,tform); imshow(I), figure, imshow(J)
Horizontal Shear
Projective Transformation. Map a square to a quadrilateral with a projective transformation:
% Set up an input coordinate system so that the input image % fills the unit square with vertices (0 0),(1 0),(1 1),(0 1). I = imread('cameraman.tif'); udata = [0 1]; vdata = [0 1]; % Transform to a quadrilateral with vertices (4 2),(8 3), % (3 5),(6 3). tform = maketform('projective',[ 0 0; 1 0; 1 1; 0 1],... [4 2; 8 3; 3 5; 6 3]); % Fill with gray and use bicubic interpolation. % Make the output size the same as the input size. [B,xdata,ydata] = imtransform(I, tform, 'bicubic', ... 'udata', udata,... 'vdata', vdata,... 'size', size(I),... 'fill', 128); subplot(1,2,1), imshow(I,'XData',udata,'YData',vdata), ... axis on subplot(1,2,2), imshow(B,'XData',xdata,'YData',ydata), ... axis on
Projective Transformation
Image Registration. Register an aerial photo to an orthophoto.
Read an aerial photo into the MATLAB workspace and view it.
unregistered = imread('westconcordaerial.png'); figure, imshow(unregistered)
Aerial Photo
Read an orthophoto into the MATLAB workspace and view it.
figure, imshow('westconcordorthophoto.png')
Orthophoto
Load control points that were previously picked.
load westconcordpoints
Create a transformation structure for a projective transformation using the points.
t_concord = cp2tform(movingPoints,fixedPoints,'projective');
Get the width and height of the orthophoto, perform the transformation, and view the result.
info = imfinfo('westconcordorthophoto.png'); registered = imtransform(unregistered,t_concord,... 'XData',[1 info.Width], 'YData',[1 info.Height]); figure, imshow(registered)
Transformed Image
checkerboard
 cp2tform
 imresize
 imrotate
 makeresampler
 maketform
 tformarray