Hessian matrix 的理解計算和實現(matlab)

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章