is there any way to compute the matrix logarithm in OpenCV? I understand that it's not available as a library function, but, pointers to a good source (paper, textbook, etc) will be appreciated.
-
1If your matrix is assumed to be symmetric and positive definite, then its symmetric positive definite logarithm is easily obtained by diagonalization. – Alexandre C. May 26 '11 at 12:07
-
Thanks, but my matrices are just diagonalizable not positive definite or symmetric. Not sure if OpenCV's eigen decomposition returns eigen-vectors which diagonalizes the matrix. I'll check it out though, in case it does return the diagonalizing matrix, your idea simplifies it very much. – Anil CR May 26 '11 at 13:08
-
["Functions of Matrices: Theory and Computation"](http://www.amazon.com/Functions-Matrices-Nicholas-J-Higham/dp/0898716462) by Nicholas J. Higham has an entire chapter (Ch 11) devoted to the matrix logarithm. It includes descriptions of algorithms and results of numerical experiments. – NPE May 26 '11 at 11:05
2 Answers
As a matter of fact, I'm in the process of programming the matrix logarithm in the Eigen library which is apparently used in some Willow Garage libraries; not sure about OpenCV. Higham's book (see answer by aix) is the best reference in my opinion and I'm implementing Algorithm 11.11 in his book. That is a rather complicated algorithm though.
Diagonalization (as in Alexandre's comment) is an easy-to-program method which works very well for symmetric positive definite matrices. It also works well for many general matrices. However, it is not accurate for matrices whose eigenvalues are close together, and it fails for matrices that are not diagonalizable.
If you want something more robust than diagonalization but less complicated than Higham's Algorithm 11.11 then I'd recommend to do a Schur decomposition followed by inverse scaling and squaring. This is Algorithm 11.10 in Higham's book, and described in the paper "Approximating the Logarithm of a Matrix to Specified Accuracy" (http://dx.doi.org/10.1137/S0895479899364015, preprint at http://eprints.ma.man.ac.uk/318/).

- 4,492
- 26
- 23
-
Thanks Jitse, But since my matrices are in [SE(3)](http://en.wikipedia.org/wiki/Euclidean_group), a simple diagonalization based function should still work well enough. – Anil CR May 28 '11 at 12:52
-
I'd expect there to be a special formula for this case, since there is a formula for the matrix logarithm of a matrix in SO(3). – Jitse Niesen May 31 '11 at 11:06
If you use OpenCV matrices, you can easily map them to Eigen3 matrices. See this post:
OpenCV CV::Mat and Eigen::Matrix
Then, Eigen3 library has a matrix logarithm function that you can use:
http://eigen.tuxfamily.org/dox/unsupported/group__MatrixFunctions__Module.html
it is under the unsupported module, but this is not an issue, this just means:
These modules are contributions from various users. They are provided "as is", without any support.
Hope this is of help.