It is possible to use the function "cp2tform" to get a 'tform' structure and use it as an input to the function "tformfwd". However, the documentation for the function "cp2tform" recommends using the function "fitgeotrans" instead. The function "fitgeotrans" returns a 'tform' object, which is not a valid input to the function "tformfwd". This issue can be resolved by using the function "transformPointsForward" instead of "tformfwd".
The following is an example of how one can use the function "fitgeotrans" followed by "transformPointsForward" instead of "cp2tform" followed by "tformfwd". The only additional step required in the new workflow is to create a 'projective2d' object from the 'tform' object returned by the function "fitgeotrans". This 'projective2d' object is a valid input to the function "transformPointsForward".
Example:
Please refer to the following example that shows how to use the function "cp2tform":
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');
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);
In this example, an image is transformed and the function "cp2tform" is used to return the transformation as a 'tform structure'. Subsequently, the angle and scale of the 'tform' is obtained using the function "tformfwd", and compared to the angle and scale of the original transformation.
The MATLAB script "usingFITGEOTRANS.m" demonstrates how the same example can be rewritten using functions "fitgeotrans" and "transformPointsForward".
Please note the following key differences in these two examples:
(1) Using the function "fitgeotrans" instead of "cp2tform":
t = cp2tform(movingPoints,fixedPoints,'nonreflective similarity');
t = fitgeotrans(movingPoints,fixedPoints,'nonreflectivesimilarity');
(2) Creating a 'projective2d' object from the 'tform' object, and using it with the function "transformPointsForward" instead of "tformfwd":
[x, y] = tformfwd(t, u, v);
projectiveObj = projective2d(t.T);
[x, y] = transformPointsForward(projectiveObj, u, v);
Best Answer