# imtransform

(Not recommended) Apply 2-D spatial transformation to image

`imtransform`

is not recommended. Use `imwarp`

instead for 2-D and 3-D transformations. Use `tformarray`

for higher dimensional transformations.

## Syntax

## Description

transforms image `B`

= imtransform(`A`

,`tform`

)`A`

according to the 2-D spatial transformation
defined by `tform`

, and returns the transformed image,
`B`

.

If `A`

is a color image, then `imtransform`

applies the same 2-D transformation to each color channel. Likewise, if
`A`

is a volume or image sequence with three or more dimensions,
then `imtransform`

applies the same 2-D transformation to all 2-D
planes along the higher dimensions.

uses name-value pairs to control various aspects of the spatial transformation.`B`

= imtransform(___,`Name,Value`

)

`[`

also returns the extent of the output image `B`

,`xdata`

,`ydata`

] = imtransform(___)`B`

in the output X-Y
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`

name-value pair input arguments.

## Examples

### Simple Transformation

Apply a horizontal shear to a grayscale image.

I = imread('cameraman.tif'); tform = maketform('affine',[1 0 0; .5 1 0; 0 0 1]); J = imtransform(I,tform); imshow(J)

### 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) subplot(1,2,2); imshow(B,'XData',xdata,'YData',ydata)

### Image Registration

Read an aerial photo into the MATLAB^{®} workspace and view it.

```
unregistered = imread('westconcordaerial.png');
figure
imshow(unregistered)
```

Read an orthophoto into the MATLAB workspace and view it.

```
figure
imshow('westconcordorthophoto.png')
```

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)

## Input Arguments

## Output Arguments

## Tips

**Image Registration.**The`imtransform`

function automatically shifts the origin of your output image to make as much of the transformed image visible as possible. If you use`imtransform`

to do image registration, the syntax`B = imtransform(A,tform)`

can produce unexpected results. To control the spatial location of the output image, set`XData`

and`YData`

explicitly.**Pure Translation.**Calling the`imtransform`

function with a purely translational transformation results in an output image that is exactly like the input image unless you specify`XData`

and`YData`

values in your call to`imtransform`

. For example, if you want the output to be the same size as the input revealing the translation relative to the input image, call`imtransform`

as shown in the following syntax:B = imtransform(A,T,'XData',[1 size(A,2)],... 'YData',[1 size(A,1)])

For more information about this topic, see Perform Simple 2-D Translation Transformation.

**Transformation Speed.**If you do not specify the output-space location for`B`

using`XData`

and`YData`

, then`imtransform`

estimates the location automatically using the function`findbounds`

. You can use`findbounds`

as a quick forward-mapping option for some commonly used transformations, such as affine or projective. For transformations that do not have a forward mapping, such as polynomial transformations computed by`fitgeotrans`

,`findbounds`

can take much longer. If you can specify`XData`

and`YData`

directly for such transformations, then`imtransform`

may run noticeably faster.**Clipping.**The automatic estimate of`XData`

and`YData`

using`findbounds`

sometimes clips the output image. To avoid clipping, set`XData`

and`YData`

directly.

## See Also

`checkerboard`

| `imresize`

| `imrotate`

| `maketform`

| `makeresampler`

| `tformarray`

**Introduced before R2006a**