%read model and image
Img=imread(“*.jpg”,'jpg’);
Mdl=imread(“*.jpg”,'jpg’);
%get just only one channel
Img=Img(1:end,1:end,1);
Mdl=Mdl(1:end,1:end,1);
%make the two images have same size
(wid,hgh)=size(Img);
(twid,thgh)=size(Mdl);
mMdl=zeros(wid,hgh);
xstart=(wid-twid)+1;
ystart=(hgh-thgh)+1;
mMdl(xstart:(xstart+twid-1),ystart:(ystart+thgh-1))=Mdl;
%Fourer transform
IF=fft2(Img);
TF=fft2(mMdl);
%in case of overflow
rnumerator=abs(IF.*TF);
tem=(rnumerator==0);
rnumerator=rnumerator+tem;
tem=1-tem;
%get the ratio of registration (re)
Ra=IF.*conj(TF)/rnumerator;
re=ifft(Ra);
re=re.*tem;
Pos=GetMaxPos(re);