%This illustrates the effect of different cutoff spatial
%frequencies in denoising by brick-wall lowpass filtering.
%Colors are different from textbook images in Fig. 6-3.
clear;load letters.mat;Y=X+500*rand(256,256);%Add noise to letters image.
FY=fft2(Y);
figure,imagesc(Y),colormap(gray),axis off,title('Moisy image')
figure,imagesc(fftshift(abs(10*log10(FY)))),axis off,title('Spectrum of noisy image')
L=75;FY(L:258-L,:)=0;FY(:,L:258-L)=0;Y=real(ifft2(FY));%Cutoff frequency=Omega_c=2(pi)75/256
figure,imagesc(Y),colormap(gray),axis off,title('Filtered image with \Omega_c=75\pi/128')
figure,imagesc(fftshift(abs(10*log10(FY)))),axis off,title('Spectrum of filtered image with \Omega_c=75\pi/128')

L=50;FY(L:258-L,:)=0;FY(:,L:258-L)=0;Y=real(ifft2(FY));%Cutoff frequency=Omega_c=2(pi)50/256
figure,imagesc(Y),colormap(gray),axis off,title('Filtered image with \Omega_c=50\pi/128')
figure,imagesc(fftshift(abs(10*log10(FY)))),axis off,title('Spectrum of filtered image with \Omega_c=50\pi/128')

L=25;FY(L:258-L,:)=0;FY(:,L:258-L)=0;Y=real(ifft2(FY));%Cutoff frequency=Omega_c=2(pi)25/256
figure,imagesc(Y),colormap(gray),axis off,title('Filtered image with \Omega_c=25\pi/128')
figure,imagesc(fftshift(abs(10*log10(FY)))),axis off,title('Spectrum of filtered image with \Omega_c=25\pi/128')



