tformfwd and tforminv - what's the difference?
Suppose I have an arbitrary transformation matrix A such as,
A =
0.9966 0.0007 -6.5625
0.0027 0.9938 1.0598
0 0 1.0000
And a set of points such that their x and y coordinates are represented by X
an开发者_开发问答d Y
respectively.
And suppose,
[Xf Yf] = tformfwd(maketform('projective',A),X,Y);
Now,
[Xff Yff] = tformfwd(maketform('projective',inv(A)),Xf,Yf);
[Xfi Yfi] = tforminv(maketform('projective',A),Xf,Yf);
[Xff Yff]
and [Xfi Yfi]
seem to be exactly the same (and they should).
Is tforminv
just there for convenience or am I missing something here?
I'll preface this by saying it is my best guess...
It's possible that tforminv
may perform the transformation without actually forming the inverse matrix. For example, you can solve a system of linear equations Ax = b
in two ways:
x = inv(A)*b;
x = A\b;
According to the documentation for inv
, the second option (using the matrix division operator) can perform better "from both an execution time and numerical accuracy standpoint" since it "produces the solution using Gaussian elimination, without forming the inverse". tforminv
may do something similar and thus show better overall behavior compared with passing the inverse matrix to tformfwd
.
If you were so inclined, you could probably try a number of different transformation matrices and test the two approaches (tforminv
or tformfwd
and inv
) to see how accurate the results are and how fast they are each computed.
精彩评论