Documentation |
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')
TFORM = cp2tform(movingPoints,fixedPoints, transformtype) infers a spatial transformation from control point pairs and returns this transformation as a TFORM structure.
TFORM = cp2tform(CPSTRUCT, transformtype) works on a CPSTRUCT structure that contains the control point matrices for the input and base images. The Control Point Selection Tool, cpselect, creates the CPSTRUCT.
[TFORM, movingPoints, fixedPoints] = cp2tform(CPSTRUCT, ...) returns the control points that were used in movingPoints and fixedPoints. Unmatched and predicted points are not used. See cpstruct2pairs.
TFORM = cp2tform(movingPoints,fixedPoints, 'polynomial', order) lets you specify the order of the polynomials to use.
TFORM = cp2tform(CPSTRUCT,'polynomial',order) works on a CPSTRUCT structure.
TFORM = cp2tform(movingPoints,fixedPoints,'piecewise linear') creates a Delaunay triangulation of the base control points, and maps corresponding input control points to the base 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(CPSTRUCT,'piecewise linear') works on a CPSTRUCT structure.
TFORM = cp2tform(movingPoints,fixedPoints,'lwm', N) 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, 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 ill-conditioned polynomials.
TFORM = cp2tform(CPSTRUCT, 'lwm', N) works on a CPSTRUCT structure.
[TFORM, movingPoints, fixedPoints, movingPoints_bad, fixedPoints_bad] = cp2tform(movingPoints, fixedPoints, 'piecewise linear') returns the control points that were used in movingPoints and fixedPoints and the control points that were eliminated because they were middle vertices of degenerate fold-over triangles in movingPoints_bad and fixedPoints_bad.
[TFORM, movingPoints, fixedPoints, movingPoints_bad, fixedPoints_bad] = cp2tform(CPSTRUCT, 'piecewise linear') works on a CPSTRUCT structure.
movingPoints |
m-by-2, double matrix containing the x- and y-coordinates of control points in the image you want to transform. |
fixedPoints |
m-by-2, double matrix containing the x- and y-coordinates of control points in the base image. |
transformtype |
Specifies the type of spatial transformation to infer. The cp2tform function requires a minimum number of control point pairs to infer a structure of each transform type. The following table lists all the transformation types supported by cp2tform in order of complexity. The 'lwm' and 'polynomial' transform types can each take an optional, additional parameter. |
CPSTRUCT |
Structure containing control point matrices for the input and base images. Use the Control Point Selection Tool (cpselect) to create the CPSTRUCT. |
'polynomial',order |
Specifies the order of polynomials to use. order can be 2, 3, or 4. Default: 3 |
'piecewise linear' |
Linear for each piece and continuous, not continuously differentiable. |
'lwm' |
Local weighted mean. |
N |
Number of points. |
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)
[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