-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgauss2.m
29 lines (24 loc) · 851 Bytes
/
gauss2.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
function gauss = gauss2(halfWidthY, widthY, halfWidthX, widthX)
% gauss2(halfWidthY, widthY, halfWidthX, widthX)
% Returns a 2D Gaussian matrix. The gaussian sums to one.
% The halfwidth must be greater than one.
%
%
% The halfwidth specifies the width of the gaussian between the points
% where it obtains half of its maximum value. The width indicates the
% gaussians width in pixels.
%
% Rick Anthony
% 8/24/93
if(nargin < 3)
halfWidthX = halfWidthY;
widthX = widthY;
end
alphaX = 2*sqrt(log(2))/(halfWidthX-1);
alphaY = 2*sqrt(log(2))/(halfWidthY-1);
%x = meshdom((1:widthX)-round(widthX/2), 1:widthY);
%y = meshdom((1:widthY)-round(widthY/2), 1:widthX)';
[x y] = meshgrid((1:widthX)-round(widthX/2),(1:widthY)-round(widthY/2));
r = sqrt(alphaX*alphaX*x.*x + alphaY*alphaY*y.*y);
gauss = exp(-r.*r);
gauss = gauss/sum(sum(gauss));