%Peforms brick-wall 2-D lowpass filtering of color image
%'toucan.jpg' with cutoff wavenumber of Omega in both directions.
clear;X=imread('toucan.jpg');X=double(X);[N,M,D]=size(X);%Know D=3.
Omega=pi/4;%Omega=cutoff wavenumber.
KN=round(Omega*N/2/pi);KM=round(Omega*M/2/pi);FX=fft2(X);
FX(KN:N+2-KN,:,:)=0;FX(:,KM:M+2-KM,:)=0;Y=real(ifft2(FX));
X=(X-min(min(min(X))))/(max(max(max(X)))-min(min(min(X))));%Scale for imagesc.
Y=(Y-min(min(min(Y))))/(max(max(max(Y)))-min(min(min(Y))));%Scale for imagesc.
FXR=(FX(:,:,1)-min(min(FX(:,:,1))))/(max(max(FX(:,:,1)))-min(min(FX(:,:,1))));%Scale for imagesc.
figure,imagesc(X),axis off,title('Original image')
figure,imagesc(fftshift(log10(abs(FX(:,:,1))))),axis off,...
title('Magnitude of spectrum of red component of filtered image')
figure,imagesc(Y),axis off,title('Filtered image')