%Reads in a square color image and produces a larger (magnified) version of it.
%Original is MXM. Upsampled is MuXMu. Mu need not be an integer multiple of M.
%Do each RGB color component separately.
clear;X=imread('toucan.jpg');X=double(X);Mu=400;%Upsampled is MuXMu.Make square:
X=X(1:336,1:336,:);X=(X-min(min(min(X))))/(max(max(max(X)))-min(min(min(X))));
M=size(X,1);figure,imagesc(X),title('Original image')%Note axes
FX=fft2(X)*Mu/M;FY(Mu,Mu,1:3)=0;%Deal with even and odd M separately:
if(2*floor(M/2)==M-1);MU=[1:(M+1)/2 (Mu+2)-(M+1)/2:Mu];FY(MU,MU,:)=FX;end;%M odd
if(2*floor(M/2)==M);MU=[1:M/2 Mu+2-M/2:Mu];MM=[1:M/2 (M/2+2):M];FY(MU,MU,:)=FX(MM,MM,:);
end;%M even; just omit Omega_i=pi components of original image (makes things simpler).
Y=real(ifft2(FY));Y=(Y-min(min(min(Y))))/(max(max(max(Y)))-min(min(min(Y))));%for imagesc.
figure,imagesc(Y),title('Upsampled image')%Note axes

