%This produces the figures in the 2-D sampling examples in Section 3-5
clear;load clown.mat;FX=fft2(X);
%Reconstruction Example 1A (Nyquist sampled):
figure,imagesc(X),colormap(gray),axis off,title('Bandlimited image f(x,y)')
figure,imagesc(fftshift(log10(abs(FX)))),colormap(gray),axis off,title('Spectrum F(\mu,\nu) of image f(x,y)')
XX(400,400)=0;XX(1:2:400,1:2:400)=X;FXX=fft2(XX);
figure,imagesc(XX),colormap(gray),axis off,title('Nyquist-sampled image f_s(x,y)')
figure,imagesc(log10(fftshift(abs(FXX)))),colormap(gray),axis off,title('Spectrum F(\mu,\nu) of sampled image')
%Reconstruction using lowpass filter:
FXX(101:301,:)=0;FXX(:,101:301)=0;XR=real(ifft2(FXX));
figure,imagesc(XR),colormap(gray),axis off,title('LPF reconstructed image f_{rec}(x,y)')
figure,imagesc(log10(fftshift(abs(FXX)))),colormap(gray),axis off,title('Lowpass-filtered spectrum')
%Example 1B: Reconstruction using Nearest-Neighbor (NN) interpolation instead of lowpass filter
H=ones(4,4)*16;Q=conv2(XX,H);figure,imagesc(Q),colormap(gray),axis off,title('Nearest-neighbor reconstructed image')

%Reconstruction Example 2A (Sub-Nyquist sampled):
figure,imagesc(X),colormap(gray),axis off,title('Bandlimited image f(x,y)')
figure,imagesc(fftshift(log10(abs(FX)))),colormap(gray),axis off,title('Spectrum F(\mu,\nu) of image f(x,y)')
ZZ(200,200)=0;ZZ(1:2:200,1:2:200)=X(1:2:200,1:2:200);FZZ=fft2(ZZ);
figure,imagesc(ZZ),colormap(gray),axis off,title('Sub-Nyquist-sampled image f_s(x,y)')
figure,imagesc(log10(fftshift(abs(FZZ)))),colormap(gray),axis off,title('Spectrum F(\mu,\nu) of sampled image')
%Reconstruction using lowpass filter:
FZZ(:,51:151)=0;FZZ(51:151,:)=0;ZR=real(ifft2(FZZ));
figure,imagesc(ZR),colormap(gray),axis off,title('LPF reconstructed image f_{rec}(x,y)')
figure,imagesc(log10(fftshift(abs(FZZ)))),colormap(gray),axis off,title('Lowpass-filtered spectrum')
%Example 2B: Reconstruction using Nearest-Neighbor (NN) interpolation instead of lowpass filter
H=ones(4,4)*16;Q=conv2(ZZ,H);figure,imagesc(Q),colormap(gray),axis off,title('Nearest-neighbor reconstructed image')





