%Rotates image X of size N clockwise by theta.
%Also magnifies by sqrt(2) (makes code simpler).
%Also morphs image X by exp(-|indices|/S).
%N must be odd so center can be shifted to origin.
%X should be 0-padded by x2 in both directions.
%Then warps image X by exp(-|indices|/S).
clear;load clown.mat;theta=pi/4;
XX(101:300,101:300)=X;XX(401,401)=0;N=size(XX,1);S=(N+1)/2;%0-pad clown image.
Y1(N,N)=0;Y2(N,N)=0;Y3(N,N)=0;Y4(N,N)=0;Y5(N,N)=0;%Initialize transformed images to zeros.
A=[cos(theta),-sin(theta);sin(theta),cos(theta)];%Rotation matrix.
I=[floor([0:N^2-1]/N)',mod([0:N^2-1],N)']+1;I=I-S;J1=round(I*A/sqrt(2));%Shift to origin; rotate by theta.
%Warp image using various transformations:
J2=round(I.*exp(-abs(I/300)));J3=round(I.*exp(-abs(I/200)));
J4=round(I.*sqrt(abs(I))/25);J5=round(I.*abs(I)/300);
I=I+S;J1=J1+S;J2=J2+S;J3=J3+S;J4=J4+S;J5=J5+S;%Shift to origin. Use NN interpolation:
Y1(N*(I(:,1)-1)+I(:,2))=XX(N*(J1(:,1)-1)+J1(:,2));Y2(N*(I(:,1)-1)+I(:,2))=XX(N*(J2(:,1)-1)+J2(:,2));
Y3(N*(I(:,1)-1)+I(:,2))=XX(N*(J3(:,1)-1)+J3(:,2));Y4(N*(I(:,1)-1)+I(:,2))=XX(N*(J4(:,1)-1)+J4(:,2));
Y5(N*(I(:,1)-1)+I(:,2))=XX(N*(J5(:,1)-1)+J5(:,2));
figure,imagesc(XX),colormap(gray),axis off,title('Zero-padded clown image')
figure,imagesc(Y1),colormap(gray),axis off,title('Clown image rotated by 45 degrees')
figure,imagesc(Y2),colormap(gray),axis off,title('Transformation: T_n(n)=nexp(-|n|/300)')
figure,imagesc(Y3),colormap(gray),axis off,title('Transformation: T_n(n)=nexp(-|n|/200)')
figure,imagesc(Y4),colormap(gray),axis off,title('Transformation: T_n(n)=nsqrt(|n|)/25')
figure,imagesc(Y5),colormap(gray),axis off,title('Transformation: T_n(n)=n|n|/300')

