GRD2HESS - Hessian matrix from directional derivatives.

Contents

Syntax

     [gxx, gyy, gxy] = GRD2HESS(gx, gy);
     [gxx, gyy, gxy] = GRD2HESS(gx, gy, rho);
     [gxx, gyy, gxy] = GRD2HESS(gx, gy, rho, ...
                                        'Property', propertyvalue, ...);

Inputs

I : an input image with size (X,Y,C), with C>1 for multispectral image.

gx, gy : directional derivatives; depending on parameter axis (see below), gx and gy are either:

typically, derivatives can be estimated using [gy,gx]=GRADIENT(I) or [gx,gy]=GRDSMOOTH(I,...,'axis','ij').

rho : post-smoothing standard deviation; this parameter sets the integration scale for spatial averaging, that controls the size of the neighbourhood in which an orientation is dominant; it is used for averaging the partial directional derivatives; if rho<0.05, then no smoothing is performed; default: rho=1.

der : optional string setting the method used for (Canny-like) smoothing and differentiating the image; it can be:

default: der='fast'.

int : optional string setting the method used for integrating (spatially averaging) the GST; smoothing is performed, which can be either isotropic, performed in local isotropic neighbourhoods, by setting it to:

or anisotropic, to better capture edges anisotropy, by setting it to:

if no smoothing needs to be performed, int can be set to false: this is equivalent to setting rho=0; default: int='fast' or, equivalently, int=true; see function SMOOTHFILT.

Property [propertyname propertyvalues]

'axis' : string indicating the direction/orientation of the input directional derivatives (see above); in particular, calls to GRD2GST(gx,gy,...,'axis','ij') and GRD2GST(gy,-gx,...,'axis','xy') are equivalent; default: axis='ij', ie. the vector orthogonal to the (real) gradient is passed.

'hsize' : optional filter size; default: estimated depending on sigma, typically hsize=6*sigma+1.

'samp' : if the gradients are interpolated gradients to avoid aliasing, the filters need to be adapted using this sampling factor; default: samp=1.

'thez', 'sigt' : parameters used by the anisotropic filtering with hour-glass filters (see HOURGLASSKERNEL); default: thez=16, sigt=.4.

'tn' : optional flag (true or false) to normalize the tensor prior to its smoothing; default: tn=false.

Outputs

gxx, gyy, gxy : matrices storing the entries of the Hessian:

                | gxx   gxy |
          H  =  |           |
                | gxy   gyy |

See also

Ressembles: GRD2GST. Requires: GRD2HESS_BASE.

Function implementation

function [gxx, gyy, gxy] = grd2hess(gx, gy, varargin)

parsing and checking parameters

error(nargchk(2, 25, nargin, 'struct'));
error(nargoutchk(3, 3, nargout, 'struct'));

if ~(isnumeric(gx) && isnumeric(gy))
    error('grd2hess:inputerror','matrices are required in input');
end

p = createParser('GRD2HESS');   % create an instance of the inputParser class.
% optional parameters
p.addOptional('rho',1., @(x)x>=0);
p.addOptional('der', 'fast', @(x)islogical(x) || (ischar(x) && ...
    any(strcmpi(x,{'matlab','vista','fast','conv','diag', ...
    'tap5','sob','opt','ana'}))));
p.addOptional('int', 'fast', @(x)islogical(x) || (ischar(x) && ...
    any(strcmpi(x,{'matlab','conv','fast','ani'}))));
p.addParamValue('hsize',[], @(x)isscalar(x) || isempty(x));
p.addParamValue('samp',1, @(x)isscalar(x) && round(x)==x && x>=1);
p.addParamValue('tn', false, @(x)islogical(x));
p.addParamValue('thez', 16, @(x)isscalar(x) && round(x)==x);
p.addParamValue('sigt', .4, @(x)isscalar(x) && isfloat(x) && x>0);
p.addParamValue('axis','ij',@(x)ischar(x) && any(strcmpi(x,{'ij','xy'})));

% parse and validate all input arguments
p.parse(varargin{:});
p = getvarParser(p);

checking parameters and setting variable

if size(gx) ~= size(gy)
    error('grd2hess:inputerror','matrices must have same dimensions');
end

if strcmp(p.axis,'ij')
    % take the vector orthogonal to the input gradient
    tmp = gx; gx = gy; gy = -tmp;
    % otherwise: horizontal OE and vertical SN derivatives have been passed
    % in gx and gy resp.
end

main computation

[gxx, gyy, gxy] = grd2hess_base(gx, gy, p.rho, p.der, p.int, ...
    p.hsize, p.samp, p.tn, p.thez, p.sigt);
end %  end of grd2hess