function mask = gauss2d(w,sigma)
% generates a normalized centered gaussian mask with size w x w and 
% center w/2,w/2 and variance sigma

vec = [(-w/2)+0.5:1:w/2-0.5];
[x y] = meshgrid(vec,vec);
x = x(:); y = y(:);
xy = [x';y']';
% calculate norm pdf with equal covariances
g = mvnpdf(xy, [0 0], sigma*eye(2));
% normalize
g = g/sum(sum(g));
% reshape it back into our matrix
g = reshape(g,[w w]);
mask = g;