1

By wikipedia http://en.wikipedia.org/wiki/Hessian_matrix , it is defined to be the square matrix of second order partial derivative of a function.

Can anybody tell me if it's correct?

[i,j]=gradient(im);
filt1=(1./2).*[1,0,-1;0,0,0;1,0,-1];
filt2=(1./2).*[-1,0,-1;0,0,0;1,0,1];
ii=(conv2(filt1,i));
jj=(conv2(filt2,j));

Gx=conv2(ii,im); % Gradient of the image in x-axis
Gy=conv2(jj,im); % Gradient of the image in y-axis


dif_Gx = conv2(f_x,a); % Gradient differentiation of the image in x-axis
dif_Gy = conv2(f_y,a); % Gradient differentiation of the image in y-axis

% Calculate second derivative
Gxx = Gx.^2;
Gyy = Gy.^2;
Gxy = Gx.*Gy;
4

2 回答 2

1

我尝试了上面提出的@Matt J 的方法,似乎代码存在尺寸不匹配问题。我将第 3 行和第 4 行修改为

Hxx(2:m-1,1:end) = diff(im,2,1);
Hyy(1:end,2:n-1) = diff(im,2,2);

现在它正在工作。

于 2015-02-16T18:32:36.750 回答
0

每个像素的 Hessian 矩阵将是一个 2 x 2 形式的矩阵[Hxx, Hxy; Hyx, Hyy]。您可以通过执行以下操作以矢量化方式跨所有像素计算这些数据值:

[m,n]=size(im);

[Hxx,Hyy,Hxy,Hyx]=deal(zeros(m,n));

Hxx(2:m-1,2:n-1) = diff(im,2,1);
Hyy(2:m-1,2:n-1) = diff(im,2,2);

tmp = diff(diff(im,1,1),1,2);    
Hxy(2:m-1,2:n-1) = tmp(2:end,2:end);

tmp = diff(diff(im,1,2),1,1);    
Hyx(2:m-1,2:n-1) = tmp(2:end,2:end);

这些计算假设您对单方面的差异感到满意。im您还可以与中心差分核进行卷积,例如k = [1 0 -1]近似一阶导数,然后第二次获得二阶导数。

于 2014-02-05T14:38:41.950 回答