Reputation: 1255
Using MATLAB, I calculate a PolynomialTransformation2D object between two images like so:
transMat = fitgeotrans(movingPoints,fixedPoints,'polynomial',3);
This gives me a geometric transformation, which I can use to register one image (the moving image - thats where the movingPoints came from) to another image (the fixed image - thats where the fixed points came from). Therefore, I can also use this transformation to map points (called A
) from the moving image to the fixed image (then called B
).
With other transformation objects like from class "projective2d" this works as follows:
B = transformPointsForward(transMat ,A);
For "PolynomialTransformation2D" this however does not work. The only thing I have found was:
B = transformPointsInverse(transMat ,A);
But then the points in B have negative coordinates and obviously are wrong. What is the correct way to do this?
Upvotes: 0
Views: 1054
Reputation: 1775
You can just reverse the transformation, i.e. calculate:
transMat = fitgeotrans(fixedPoints,movingPoints,'polynomial',3);
And then transform the points using tranformPointInverse
.
The reason you don't have transformPointsForward
is that as opposed to similarity, affine, and projective transformations, the polynomial transformation is not trivially invertible. Remember that, like you said, the transformation object represents the transformation from the 'moving' image to the 'fixed' one. However, the polynomial itself describes the calculation of coordinates in the 'moving' image based on coordinates in the 'fixed' image.
So, as written in the documentation, underlying the transformation object are 2 sets of polynomial coefficients (A
and B
), such that:
U = A(1) + A(2).*X + A(3).*Y + A(4).*X.*Y + A(5).*X.^2 + A(6).*Y.^2 +...
V = B(1) + B(2).*X + B(3).*Y + B(4).*X.*Y + B(5).*X.^2 + B(6).*Y.^2 +...
where X
and Y
are the coordinates in the 'fixed' image and U
and V
are the coordinates in the 'moving' image.
Looking at these you can see that it's easy to transform points 'backward' - you just plugin the values instead of X
and Y
in the formulas above and get U
and V
. However, it's not as easy (and not always possible) to transform 'forward' - given X
and Y
solve the equations above (which may be 3rd - 5th order) to get a unique solution for U
and V
.
Upvotes: 1