Infer spatial transformation from control point pairs

`cp2tform`

is not recommended. Use `fitgeotrans`

instead.

infers a spatial transformation from control point pairs and returns this transformation as a
`tform`

= cp2tform(`movingPoints`

,`fixedPoints`

,`transformationType`

)`tform`

structure. Some of the transformation types have optional additional
parameters, shown in the following syntaxes.

lets you specify the order of the polynomials to use.`tform`

= cp2tform(`movingPoints`

,`fixedPoints`

,'polynomial',`degree`

)

creates a mapping by inferring a polynomial at each control point using neighboring control
points. The mapping at any location depends on a weighted average of these polynomials. You can
optionally specify the number of points, `tform`

= cp2tform(`movingPoints`

,`fixedPoints`

,'lwm',`n`

)`n`

, used to infer each polynomial.
The `n`

closest points are used to infer a polynomial of order 2 for each
control point pair.

creates a Delaunay triangulation of the fixed control points, and maps corresponding moving
control points to the fixed control points. The mapping is linear (affine) for each triangle
and continuous across the control points but not continuously differentiable as each triangle
has its own mapping.`tform`

= cp2tform(`movingPoints`

,`fixedPoints`

,'piecewise
linear')

`[`

returns in `tform`

,`usedMP`

,`usedFP`

,`badMP`

,`badFP`

] = cp2tform(`movingPoints`

,`fixedPoints`

,'piecewise
linear')`usedMP`

and `usedFP`

the control points that
were used for the piecewise linear transformation. This syntax also returns in
`badMP`

and `badFP`

the control points that were
eliminated because they were middle vertices of degenerate fold-over triangles.

uses a `tform`

= cp2tform(`cpstruct`

,`transformationType`

,___)`cpstruct`

structure to store the control point coordinates of the
moving and fixed images.

`[`

also returns in `tform`

,`usedMP`

,`usedFP`

]
= cp2tform(`cpstruct`

,`transformationType`

,___)`usedMP`

and `usedFP`

the control points
that were used for the transformation. Unmatched and predicted points are not used. See
`cpstruct2pairs`

.

Transform an image, use the `cp2tform`

function to return the
transformation, and compare the angle and scale of the `tform`

to the angle and
scale of the original transformation:

```
I = checkerboard;
J = imrotate(I,30);
fixedPoints = [11 11; 41 71];
movingPoints = [14 44; 70 81];
cpselect(J,I,movingPoints,fixedPoints);
t = cp2tform(movingPoints,fixedPoints,'nonreflective similarity');
```

Recover angle and scale by checking how a unit vector parallel to the
*x*-axis is rotated and stretched.

u = [0 1]; v = [0 0]; [x, y] = tformfwd(t,u,v); dx = x(2) - x(1); dy = y(2) - y(1); angle = (180/pi) * atan2(dy, dx) scale = 1 / sqrt(dx^2 + dy^2)

When

`transformtype`

is`'nonreflective similarity'`

,`'similarity'`

,`'affine'`

,`'projective'`

, or`'polynomial'`

, and`movingPoints`

and`fixedPoints`

(or`cpstruct`

) have the minimum number of control points needed for a particular transformation,`cp2tform`

finds the coefficients exactly.If

`movingPoints`

and`fixedPoints`

have more than the minimum number of control points, a least-squares solution is found. See`mldivide`

.When either

`movingPoints`

or`fixedPoints`

has a large offset with respect to their origin (relative to range of values that it spans),`cp2tform`

shifts the points to center their bounding box on the origin before fitting a`tform`

structure. This enhances numerical stability and is handled transparently by wrapping the origin-centered`tform`

within a custom`tform`

that automatically applies and undoes the coordinate shift as needed. As a result,`fields(T)`

can give different results for different coordinate inputs, even for the same transformation type.

[1] Goshtasby, Ardeshir, "Piecewise linear mapping functions for image
registration," *Pattern Recognition*, Vol. 19, 1986, pp.
459-466.

[2] Goshtasby, Ardeshir, "Image registration by local approximation
methods," *Image and Vision Computing*, Vol. 6, 1988, pp.
255-261.

`cpcorr`

| `cpselect`

| `cpstruct2pairs`

| `imtransform`

| `tformfwd`

| `tforminv`