%This was used to compare interpolation methods on the clown image
%decimated by 3X3 (2/3 of its values set to zero, to be interpolated).
clear;load clown;%Decimate by 3X3 (2/3 values set to 0):
Y(201,201)=0;Y(2:3:200,2:3:200)=X(2:3:200,2:3:200);
figure,imagesc(Y),colormap(gray),axis off,title('Image to interpolate')
Y1=conv2(Y,ones(3,3));Y2=conv2(Y,[1 2 3 2 1]'*[1 2 3 2 1]);
figure,imagesc(Y1),colormap(gray),axis off,title('B-spline nearest neighbor (NN)')
figure,imagesc(Y2),colormap(gray),axis off,title('B-spline linear interpolation')
FY=fft2(Y);FY(:,34:169)=0;FY(34:169,:)=0;Y3=real(ifft2(FY));%Lowpass filter
figure,imagesc(Y3),colormap(gray),axis off,title('Sinc interpolation')
%Lanczos interpolation a=2:
t2=[-2:1/3:2];H2=sin(pi*t2)./(pi*t2).*sin(pi*t2/2)./(pi*t2/2);H2(7)=1;%1-D Lanczos (a=2)
Y4=conv2(Y,H2(2:12)'*H2(2:12));%Lanczos 2-D interpolation.
figure,imagesc(Y4),colormap(gray),axis off,title('Lanczos interpolation with a=2')
%Lanczos interpolation a=3:
t3=[-3:1/3:3];H3=sin(pi*t3)./(pi*t3).*sin(pi*t3/3)./(pi*t3/3);H3(10)=1;%1-D Lanczos (a=3).
Y5=conv2(Y,H3(2:18)'*H3(2:18));%Lanczos 2-D interpolation.
figure,imagesc(Y5),colormap(gray),axis off,title('Lanczos interpolation with a=3')
%Cubic spline interpolation:
beta=[1/6 2/3 1/6];beta2=beta'*beta;%Cubic spline function samples.
t1=[1:2]/3;St1=2/3-t1.^2+t1.^3/2;t2=[3:5]/3;St2=(2-t2).^3/6;%Cubic spline function.
S=[St1 St2];S=[fliplr(S) 2/3 S];S2=S'*S;%2-D cubic spline.
C=real(ifft2(fft2(Y,201,201)./fft2(beta2,201,201)));Y6=conv2(C,S2);%Coefficients C by econvolution
figure,imagesc(Y6),colormap(gray),axis off,title('B-spline cubic spline')
