function [y,H]=gausslpf(x,Sigma)
%GAUSSLPF  Gaussian lowpass filter
%	y=gausslpf(x,Sigma) applies a Gaussian lowpass filter with passband
%	width determined by Sigma.
%	[y,H]=gausslpf(x,Sigma) return also the 2D frequency responce of the
%	filter.
%
%	The Farrokhnia approach employs Sigma=sqrt(2)*CtrFreq/pi if the
%	corresponding Gabor filter has a center frequency CtrFreq.

[VDim,HDim]=size(x);

% Determine if the input should be symmetrically extended prior to filtering
% to have power of two dimensions.
if (VDim == 2^(ceil(log2(VDim)))) & (HDim == 2^(ceil(log2(HDim)))),
  SymmExt=0;
else
  SymmExt=1;
  [x,TopMarg,BotMarg,LftMarg,RgtMarg]=symmext(x);
end

% Transform the input to the Fourier domain
X=fft2(x);
[M,N]=size(X);

% Generate the filter (in the Fourier-domain)
[j,i]=meshgrid(1:N/2,1:M/2);
i=[i i]; i=[i;-flipud(i)];
j=[j;j]; j=[j -fliplr(j)];
u=i/M;
v=j/N;
H=exp(-(u.^2 + v.^2)/(2*Sigma^2));

% Filter the image
Y=X.*H;

% Transform the filtered image back to the spatial domain
%y=M*N*ifft2(Y);
y=ifft2(Y);
y=abs(y); % Remove "rounding errors" in the imaginary part
  
% If the input has been symmetrically extended, remove the symmetric
% extension 
if SymmExt,
  y=y(TopMarg+1:TopMarg+VDim,LftMarg+1:LftMarg+HDim);
end








