


Construct a 2D Gaussian matrix.
gMatrix = gauss2(halfWidthY, supportY, halfWidthX, supportX)
You should always call this function with an odd number for the support
so that the Gaussian is symmetric (centered). In that case the
calculation here ends up being the same as the calculation used by Matlab
in fspecial. There is a slight difference for an even support.
The bivariate Gaussian formula is
g2 = (1/(2*pi*sx*sy))*exp(-(1/2)(x/sx)^2 + (y/sy)^2)
http://en.wikipedia.org/wiki/Multivariate_normal_distribution#Bivariate_ca
se
Examples:
These casese yield the same result when the support is odd.
They differ when the support is even
gG = gauss2(5, 25, 5, 25); mesh(1:25,1:25,gG)
gF = fspecial('gauss',25 ,ieHwhm2SD(5)); mesh(1:25,1:25,gF)
mesh(gG - gF)
gG = gauss2(2, 25, 2, 25); mesh(1:25,1:25,gG)
gF = fspecial('gauss',25, ieHwhm2SD(2)); mesh(1:25,1:25,gF)
mesh(gG - gF)
When the support is even, the difference is small. It occurs because of
a slight shift in the curve that we introduce to center the support.
gG = gauss2(3, 11, 3, 11); mesh(1:10,1:10,gG)
gF = fspecial('gauss',11 , ieHwhm2SD(3)); mesh(1:10,1:10,gF)
mesh(gG - gF)
gG = gauss2(8, 50, 8, 50); mesh(1:50,1:50,gG)
gF = fspecial('gauss',50 , ieHwhm2SD(8)); mesh(1:50,1:50,gF)
mesh(gG - gF)
We differ slightly fspecial, sigh. But not much.
Copyright ImagEval Consultants, LLC, 2003.