clear;X=imread('bank.png');X=double(X(13:42,:,1));X=255-X;%Digits 30X18.
I(1,:)=[17:34];I(2,:)=[50:67];I(3,:)=[78:95];I(4,:)=[111:128];I(5,:)=[140:157];
I(6,:)=[170:187];I(7,:)=[202:219];I(8,:)=[232:249];I(9,:)=[262:279];
I(10,:)=[292:299 301:310];%Cut out 1 column of ``0'' so decimation includes sides.
for K=1:10;XX(:,:,K)=X(:,I(K,:));end;XX1(4:33,3:20,:)=XX;YY=XX1(1:2:33,1:2:19,:);
ZZ=XX1([2.^[0:5]+1],[2.^[0:4]+1],:);ZY=YY([2.^[0:4]+1],[2.^[0:3]+1],:);
%Zero-pad to XX1(:,:,K)=fullsize digit K(33X20).YY(:,:,K)=halfsize digit K(17X10)
%ZZ(:,:,K)=log fullsize digit K(6X5). ZY(:,:,K)=log halfsize digit K(5X4).
YYY=[YY(:,:,1) YY(:,:,2) YY(:,:,3) YY(:,:,4) YY(:,:,5) YY(:,:,6) YY(:,:,7)];
YYY=[YYY YY(:,:,8) YY(:,:,9) YY(:,:,10)];%halfsize account number(17X100)(100=10@10)
ZZY=[ZY(:,:,1) ZY(:,:,2) ZY(:,:,3) ZY(:,:,4) ZY(:,:,5) ZY(:,:,6) ZY(:,:,7)];
ZZY=[ZZY ZY(:,:,8) ZY(:,:,9) ZY(:,:,10)];%log halfsize account number(5X40)(40=10@4)
for J1=1:10;for J2=1:10;R(J2)=2*sum(sum(ZZ(2:6,2:5,J2).*ZZY(:,[1:4]+(J1-1)*4)));
R(J2)=R(J2)-sum(sum(ZZ(2:6,2:5,J2).*ZZ(2:6,2:5,J2)));end;%shift by 1 in log scale.
[Z,D]=max(R);K(J1)=rem(D,10);end;
subplot(211),imagesc(YYY),colormap(gray),subplot(212),stem(K)

clear;X=imread('bank.png');X=double(X(13:42,:,1));X=255-X;%Digits 30X18.
I(1,:)=[17:34];I(2,:)=[50:67];I(3,:)=[78:95];I(4,:)=[111:128];I(5,:)=[140:157];
I(6,:)=[170:187];I(7,:)=[202:219];I(8,:)=[232:249];I(9,:)=[262:279];
I(10,:)=[292:299 301:310];%Cut out 1 column of ``0'' so decimation includes sides.
for K=1:10;XX(:,:,K)=X(:,I(K,:));end;XX1(4:33,3:20,:)=XX;YY=XX1(1:2:33,1:2:19,:);
ZZ=XX1([2.^[0:5]+1],[2.^[0:4]+1],:);ZY=YY([2.^[0:4]+1],[2.^[0:3]+1],:);
%Zero-pad to XX1(:,:,K)=fullsize digit K(33X20).YY(:,:,K)=halfsize digit K(17X10)
%ZZ(:,:,K)=log fullsize digit K(6X5). ZY(:,:,K)=log halfsize digit K(5X4).
YYR=[YY(:,:,2) YY(:,:,2) YY(:,:,1) YY(:,:,3) YY(:,:,7) YY(:,:,1) YY(:,:,3)];
YYR=[YYR YY(:,:,5) YY(:,:,6)];%halfsize routing number (17X90)(90=9@10).
ZYR=[ZY(:,:,2) ZY(:,:,2) ZY(:,:,1) ZY(:,:,3) ZY(:,:,7) ZY(:,:,1) ZY(:,:,3)];
ZYR=[ZYR ZY(:,:,5) ZY(:,:,6)];%log halfsize routing number (5X36)(36=9@4).
for J1=1:9;for J2=1:10;R(J2)=2*sum(sum(ZZ(2:6,2:5,J2).*ZYR(:,[1:4]+(J1-1)*4)));
R(J2)=R(J2)-sum(sum(ZZ(2:6,2:5,J2).*ZZ(2:6,2:5,J2)));end;%shift by 1 in log scale.
[Z,D]=max(R);K(J1)=rem(D,10);end;
subplot(211),imagesc(YYR),colormap(gray),subplot(212),stem(K)

clear;X=imread('bank.png');X=double(X(13:42,:,1));X=255-X;%Digits 30X18.
I(1,:)=[17:34];I(2,:)=[50:67];I(3,:)=[78:95];I(4,:)=[111:128];I(5,:)=[140:157];
I(6,:)=[170:187];I(7,:)=[202:219];I(8,:)=[232:249];I(9,:)=[262:279];
I(10,:)=[292:299 301:310];%Cut out 1 column of ``0'' so decimation includes sides.
for K=1:10;XX(:,:,K)=X(:,I(K,:));end;XX1(4:33,3:20,:)=XX;YY=XX1(1:2:33,1:2:19,:);
ZZ=XX1([2.^[0:5]+1],[2.^[0:4]+1],:);ZY=YY([2.^[0:4]+1],[2.^[0:3]+1],:);
%Zero-pad to XX1(:,:,K)=fullsize digit K(33X20). YY(:,:,K)=halfsize digit K(17X10)
%ZZ(:,:,K)=log fullsize digit K(6X5). ZY(:,:,K)=log halfsize digit K(5X4).
YYA=[YY(:,:,10) YY(:,:,1) YY(:,:,2) YY(:,:,3) YY(:,:,4) YY(:,:,5) YY(:,:,6)];
YYA=[YYA YY(:,:,7) YY(:,:,8) YY(:,:,9)];%halfsize account number (17X8100)(10@10)
ZYA=[ZY(:,:,10) ZY(:,:,1) ZY(:,:,2) ZY(:,:,3) ZY(:,:,4) ZY(:,:,5) ZY(:,:,6)];
ZYA=[ZYA ZY(:,:,7) ZY(:,:,8) ZY(:,:,9)];%log halfsize account number (5X40)(10@4)
for J1=1:10;for J2=1:10;R(J2)=2*sum(sum(ZZ(2:6,2:5,J2).*ZYA(:,[1:4]+(J1-1)*4)));
R(J2)=R(J2)-sum(sum(ZZ(2:6,2:5,J2).*ZZ(2:6,2:5,J2)));end;%shift by 1 in log scale.
[Z,D]=max(R);K(J1)=rem(D,10);end;
subplot(211),imagesc(YYA),colormap(gray),subplot(212),stem(K)



%for I=1:9,subplot(3,3,I),imagesc(XX1(:,:,I)),colormap(gray),end