Hessian矩阵的计算需要计算图像的二阶偏导数。一般地,线性尺度空间理论被用来计算Hessian矩阵的微分算子。在这个理论下,微分通常被定义为原始数据和高斯滤波器导数的卷积。二阶方向导数定义为:
function [Dxx,Dxy,Dyy] = Hessian2D(I,Sigma)
% This function Hessian2 Filters the image with 2nd derivatives of a
% Gaussian with parameter Sigma.
%
% [Dxx,Dxy,Dyy] = Hessian2(I,Sigma);
%
% inputs,
% I : The image, class preferable double or single
% Sigma : The sigma of the gaussian kernel used
%
% outputs,
% Dxx, Dxy, Dyy: The 2nd derivatives
%
% example,
% I = im2double(imread('moon.tif'));
% [Dxx,Dxy,Dyy] = Hessian2(I,2);
% figure, imshow(Dxx,[]);
if nargin < 2, Sigma = 1; end
% Make kernel coordinates
[X,Y] = ndgrid(-round(3*Sigma):round(3*Sigma));
% Build the gaussian 2nd derivatives filters
DGaussxx = 1/(2*pi*Sigma^4) * (X.^2/Sigma^2 - 1) .* exp(-(X.^2 + Y.^2)/(2*Sigma^2));
DGaussxy = 1/(2*pi*Sigma^6) * (X .* Y) .* exp(-(X.^2 + Y.^2)/(2*Sigma^2));
DGaussyy = DGaussxx';
Dxx = imfilter(I,DGaussxx,'conv');
Dxy = imfilter(I,DGaussxy,'conv');
Dyy = imfilter(I,DGaussyy,'conv');
% Dxx = imfilter(I,DGaussxx);
% Dxy = imfilter(I,DGaussxy);
% Dyy = imfilter(I,DGaussyy);
end