-
Notifications
You must be signed in to change notification settings - Fork 3
/
ImageDerivatives2D.m
32 lines (29 loc) · 976 Bytes
/
ImageDerivatives2D.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function J=ImageDerivatives2D(I,sigma,type)
% Gaussian based image derivatives
%
% J=ImageDerivatives2D(I,sigma,type)
%
% inputs,
% I : The 2D image
% sigma : Gaussian Sigma
% type : 'x', 'y', 'xx', 'xy', 'yy'
%
% outputs,
% J : The image derivative
%
% Function is written by D.Kroon University of Twente (July 2010)
% Make derivatives kernels
[x,y]=ndgrid(floor(-3*sigma):ceil(3*sigma),floor(-3*sigma):ceil(3*sigma));
switch(type)
case 'x'
DGauss=-(x./(2*pi*sigma^4)).*exp(-(x.^2+y.^2)/(2*sigma^2));
case 'y'
DGauss=-(y./(2*pi*sigma^4)).*exp(-(x.^2+y.^2)/(2*sigma^2));
case 'xx'
DGauss = 1/(2*pi*sigma^4) * (x.^2/sigma^2 - 1) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
case {'xy','yx'}
DGauss = 1/(2*pi*sigma^6) * (x .* y) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
case 'yy'
DGauss = 1/(2*pi*sigma^4) * (y.^2/sigma^2 - 1) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
end
J = imfilter(I,DGauss,'conv','symmetric');