Infer spatial transformation from control point pairs
cp2tform
is not recommended. Use fitgeotrans
instead.
TFORM = cp2tform(movingPoints,fixedPoints, transformtype)
TFORM = cp2tform(CPSTRUCT, transformtype)
[TFORM, movingPoints, fixedPoints]
= cp2tform(CPSTRUCT, ...)
TFORM = cp2tform(movingPoints,fixedPoints,
'polynomial', order)
TFORM = cp2tform(CPSTRUCT,'polynomial',order)
TFORM = cp2tform(movingPoints,fixedPoints,'piecewise
linear')
TFORM = cp2tform(CPSTRUCT,'piecewise
linear')
TFORM = cp2tform(movingPoints,fixedPoints,'lwm', N)
TFORM = cp2tform(CPSTRUCT, 'lwm', N)
[TFORM, movingPoints, fixedPoints, movingPoints_bad, fixedPoints_bad]
= cp2tform(movingPoints, fixedPoints, 'piecewise
linear')
[TFORM, movingPoints, fixedPoints, movingPoints_bad, fixedPoints_bad]
= cp2tform(CPSTRUCT, 'piecewise linear')
infers
a spatial transformation from control point pairs and returns this
transformation as a TFORM
= cp2tform(movingPoints
,fixedPoints
, transformtype
)TFORM
structure.
works
on a TFORM
= cp2tform(CPSTRUCT
, transformtype
)CPSTRUCT
structure that contains the control
point matrices for the moving and fixed images. The Control Point
Selection Tool, cpselect
, creates
the CPSTRUCT
.
[
returns
the control points that were used in TFORM
, movingPoints
, fixedPoints
]
= cp2tform(CPSTRUCT
, ...)movingPoints
and fixedPoints
.
Unmatched and predicted points are not used. See cpstruct2pairs
.
lets you specify the order of the
polynomials to use.TFORM
= cp2tform(movingPoints
,fixedPoints
,
'polynomial', order)
works
on a TFORM
= cp2tform(CPSTRUCT
,'polynomial',order
)CPSTRUCT
structure.
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'
)
works on a TFORM
= cp2tform(CPSTRUCT
,'piecewise
linear'
)CPSTRUCT
structure.
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. If you omit N
, it defaults to 12. N
can
be as small as 6, but making N
small risks generating
illconditioned polynomials.
works
on a TFORM
= cp2tform(CPSTRUCT
, 'lwm'
, N
)CPSTRUCT
structure.
[
returns the control points that were
used in TFORM
, movingPoints
, fixedPoints
, movingPoints_bad
, fixedPoints_bad
]
= cp2tform(movingPoints
, fixedPoints
, 'piecewise
linear'
)movingPoints
and fixedPoints
and
the control points that were eliminated because they were middle vertices
of degenerate foldover triangles in movingPoints_bad
and fixedPoints_bad
.
[
works on a TFORM
, movingPoints
, fixedPoints
, movingPoints_bad
, fixedPoints_bad
]
= cp2tform(CPSTRUCT
, 'piecewise linear'
)CPSTRUCT
structure.

mby2, 

mby2, 

Specifies the type of spatial transformation to infer. The 

Structure containing control point matrices for the moving and
fixed images. Use the Control Point Selection Tool ( 

Specifies the order of polynomials to use. Default: 3 

Linear for each piece and continuous, not continuously differentiable. 

Local weighted mean. 

Number of points. 

Structure containing the spatial transformation. 

Moving control points that were used to infer the spatial transformation. Unmatched and predicted points are not used. 

Fixed control points that were used to infer the spatial transformation. Unmatched and predicted points are not used. 

moving control points that were eliminated because they were determined to be outliers. 

fixed control points that were eliminated because they were determined to be outliers. 
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 xaxis 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 leastsquares 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 origincentered 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. 459466.
[2] Goshtasby, Ardeshir, "Image registration by local approximation methods," Image and Vision Computing, Vol. 6, 1988, pp. 255261.
cpcorr
 cpselect
 cpstruct2pairs
 imtransform
 tformfwd
 tforminv