eigenvalue/vectors for a group of square matrices (in 3D-form?)
18 views (last 30 days)
Hi, Now I am running into calculating the eigenvalues of Hessian of an image. For every pixel there is the 2x2 matrix that i will need to use eig() on, which involves for-looping on each pixel.
Is there a more elegent way to perform a "group eig" on a 3D matrix of, say 2x2xN without using for loop?
Thanks for any idea and suggestion.
Martin on 17 Sep 2011
Do you want to calculate the eigenvalues for the 2D Hessian or the 3D Hessian? For the 2D Hessian, you can use the following code to calculate the eigenvalues for all pixels at once.
eigVal1 = (Lxx + Lyy + sqrt((Lxx - Lyy).^2 + 4*Lxy.^2))/2;
eigVal2 = (Lxx + Lyy - sqrt((Lxx - Lyy).^2 + 4*Lxy.^2))/2;
This requires that you have already calculated the second order derivatives of the image and stored them in matrices Lxx, Lxy, Lyy.
[20 Sep 2011 - Edited to add link to 3D Hessian code]
For the 3D Hessian, it seems that there are numerical precision issues with the equivalent analytical formulae for the eigenvalues. I am currently using Dirk-Jan Kroon's code, which looks like an implementation of the QL algorithm ( http://www.mathworks.com/matlabcentral/fileexchange/24409 ). It's written as a Matlab C mex file and is pretty fast. I've just started using it, but it seems to give sensible enough results for my image processing application. You will need to have already calculated matrices containing the relevant 3D partial derivatives at each pixel. Usage is:
[eigVal1, eigVal2, eigVal3, eigVec1, eigVec2, eigVec3] = ...
eig3volume(Lxx, Lxy, Lxz, Lyy, Lyz, Lzz);
tomas on 8 Sep 2011
Hi, I asked for something similar 2 weeks ago. Try this. It works fine for my purposes, may be it will work for yours as well.