Calculating the eigenvalues of a composite matrix

9 views (last 30 days)
Hello everyone,
the problem is as follows:
I calcualted the first and second derivatives of an image (1024x1280 pixel) using imgrdarientxy.
[Gx,Gy] = imgradientxy(Bild);
[Gxx,Gxy] = imgradientxy(Gx);
[Gyx,Gyy] = imgradientxy(Gy);
Now i want to calculate the eigenvalues of the Hessian matrix, which consists of the second derivatives of the image.
Simply said it would look something like this.
HessianMatrix1 = [Gxx(1,1) Gxy(1,1); Gyx(1,1) Gyy(1,1)];
[V1,D1,W1] = eig(HessianMatrix1);
HessianMatrix2 = [Gxx(1,2) Gxy(1,2); Gyx(1,2) Gyy(1,2)];
[V2,D2,W2] = eig(HessianMatrix2);
.........
HessianMatrix1281 = [Gxx(2,1) Gxy(2,1); Gyx(2,1) Gyy(2,1)];
[V1281,D1281,W1281] = eig(HessianMatrix1281);
And so on. Basically the eigenvalues of the Hessian matrix (the second derivatives) for every pixel.
Now I don't know how to do this for the whole matrices.
I tryed it with a for loop but it only calcualtes the eigenvalue and eigenvector for the last iteration. I think I did a mistake in how the values are saved but i don't know how to fix it.
for j=1:n %n=1280
for i=1:m %m=1024
HesseM = [Gxx(i,j) Gxy(i,j); Gyx(i,j) Gyy(i,j)];
[V,D,W] = eig(HesseM);
end
end
Does anybody know how to implement this, so that it calcualtes all the eigenvalues (and eigenvectors) for every combination.
Thanks a lot,
Antonio

Accepted Answer

Sindar
Sindar on 19 Feb 2020
You are overwriting V,D,W every time. The simplest way to avoid this, ignoring the specific size of the variables, is to put the answers into a cell array:
for j=1:n %n=1280
for i=1:m %m=1024
HesseM = [Gxx(i,j) Gxy(i,j); Gyx(i,j) Gyy(i,j)];
[V{j,i},D{j,i},W{j,i}] = eig(HesseM);
end
end

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!