Determinant of hessian matrix of a grayscale image is too small in matlab

813 views Asked by At

I am trying to find determinant of hessian matrix of a 50x50 grayscale image. Determinant of matrix I am getting is a very small value i.e 4.7612e-134. I think I am missing something. My code is below. Thanks

 % computing second derivatives in each direction first

 [gx, gy] = gradient(double(sliceOfImageK2));

 [gxx, gxy] = gradient(gx);

 [gyx, gyy] = gradient(gy);

 hessianMatrix = [gxx gxy; gxy gyy];

 determinantHessianMatrix = det(hessianMatrix)
1

There are 1 answers

1
Iban Cereijo On

I don't think you should assemble a 100x100 matrix if you want to call it Hessian. Assemble instead a 2x2 matrix per each of the 50x50 (2500) pixels where you are sampling your derivatives.

These are the 2500 hessians, expressed in a 2500x4 matrix:

H = [gxx(:) gxy(:) gyx(:) gyy(:)]

Here expressed as 2500 2x2 matrices:

H_ = reshape(H', 2, 2, length(H))

And these are the determinants of each 2x2 matrix:

D = H(:,1).*H(:,4) - H(:,2).*H(:,3)

Here as a 50x50 matrix with the determinant of the Hessian at each pixel, if that is what you are after:

reshape(D, 50, 50)