%This shows how to classify a rotated bank digit image by transforming the digit to be classified
%and all of the reference bank digit images, to polar coordinates. Use only top half of each digit.
%In polar coordinates, a rotation is just a shift along the theta axis. so use cross-correlation.
clear;load bank.mat;
%Each digit XX(:,:,k) is a 30X18 portion of X. (XX is a 3D array):
%XX(:,:,k) represents digit k. (XX(:,:,10) represents 0). Digit to be classified is 3:
XX(:,:,1)=X(:,17:34);XX(:,:,2)=X(:,50:67);XX(:,:,3)=X(:,78:95);
XX(:,:,4)=X(:,111:128);XX(:,:,5)=X(:,140:157);XX(:,:,6)=X(:,170:187);
XX(:,:,7)=X(:,202:219);XX(:,:,8)=X(:,232:249);XX(:,:,9)=X(:,262:279);
XX(:,:,10)=X(:,292:309);XX1=XX(1:17,1:17,:);%Clip Digits to 17X17 for Rotation
thetao=90;for r=1:80;for theta=1:720;%thetao=CCW rotation angle. Z=XX1(:,:,3) rotated by thetao.
%Now rotate 3 and convert it to polar coordinates:
Z2(r,theta)=XX1(9-round(r/10*sin((theta-thetao)*pi/180)),9+round(r/10*cos((theta-thetao)*pi/180)),3);
Z(9-round(r/10*sin(theta*pi/180)),9+round(r/10*cos(theta*pi/180)))=Z2(r,theta);
for k=1:10;%Now convert all digits to polar coordinates:
YY(r,theta,k)=XX(9-round(r/10*sin(theta*pi/180)),9+round(r/10*cos(theta*pi/180)),k);end;end;end;
%Reference clipped images 1...9
figure,for k=1:9;subplot(3,3,k),imagesc(XX1(:,:,k)),colormap(gray);end;
%Reference clipped images 1...9 in polar coordinates:
figure,for k=1:9;subplot(3,3,k),imagesc([1 720],[0:0.1:8],YY(:,:,k)),colormap(gray);end
figure,subplot(2,2,1),imagesc(Z),colormap(gray),axis off,title('Rotated clipped 3')
subplot(2,2,2),imagesc([1 720],[0:0.1:8],Z2),colormap(gray),axis off,title('Rotated clipped 3 in polar coordinates')
%Rotated 3 in polar coordinates is clearly a shifted version of unrotated 3 in polar coordinates.
