cp2tform
(Not recommended) Infer spatial transformation from control point pairs
cp2tform
is not recommended. Use fitgeotform2d
instead.
Syntax
Description
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
.
Examples
Input Arguments
Output Arguments
Tips
When
transformtype
is'nonreflective similarity'
,'similarity'
,'affine'
,'projective'
, or'polynomial'
, andmovingPoints
andfixedPoints
(orcpstruct
) have the minimum number of control points needed for a particular transformation,cp2tform
finds the coefficients exactly.If
movingPoints
andfixedPoints
have more than the minimum number of control points, a least-squares solution is found. Seemldivide
.When either
movingPoints
orfixedPoints
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 atform
structure. This enhances numerical stability and is handled transparently by wrapping the origin-centeredtform
within a customtform
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.
Algorithms
References
[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.
Version History
Introduced before R2006a