%This shows why using a 2-D Hamming window for lowpass filtering
%is better than using a brick-wall lowpass filter (no ringing).
clear;load letters.mat;FX=fft2(X,276,276);
%0-pad the DFT since will convolve the 256X256 letters image with 21X21
%Hamming windowed lowpass filter. Result is 276X276, where 256+21-1=276.
figure,imagesc(X),colormap(gray),axis off,title('Noiseless letters image')
figure,imagesc(fftshift(log10(abs(FX)))),colormap(gray),axis off,...
title('Log of magnitude spectrum of noiseless letters image')

%Brickwall-lowpass filter with cutoff Omega_c=2(pi)32/256=pi/4.
FY=FX;FY(33:(278-33),:)=0;FY(:,33:(278-33))=0;Y=real(ifft2(FY));
figure,imagesc(Y),colormap(gray),axis off,...
title('Brickwall lowpass filtered image. Note the whorls')
figure,imagesc(fftshift(log10(abs(FY)))),colormap(gray),axis off,...
title('Log of magnitude spectrum of brickwall lowpass filtered image')

%Hamming-windowed lowpass filter with cutoff Omega_c=2(pi)35/256.
H=(0.54+0.46*cos(pi*[-10:10]/10)).*sin(pi/4*[-10:10])./[-10:10]/pi;%1-D Hamming window.
H(11)=1/4;H2=H'*H;FH2=fft2(H2,276,276);%(21X21) 2-D Hamming window.
FZ=FH2.*FX;Z=real(ifft2(FZ));%Apply (21X21) 2-D Hamming window.
figure,imagesc(Z),colormap(gray),axis off,...
title('Hamming lowpass filtered image. Note no whorls')
figure,imagesc(fftshift(log10(abs(FZ)))),colormap(gray),axis off,...
title('Log of magnitude spectrum of Hamming-windowed lowpass filtered image')




