function C=corr(image,template)
[mi,ni]=size(image);
[mt,nt]=size(template);
C=zeros(mi-mt+1,ni-nt+1);
for u=1:mi-mt+1
for v=1:ni-nt+1
a=0;
b=0;
c=0;
for i=1:mt
for j=1:nt
a=a+image(i+u-1,j+v-1)*template(i,j);
b=b+image(i+u-1,j+v-1)*image(i+u-1,j+v-1);
c=c+template(i,j)*template(i,j);
end
end
b=sqrt(b);
c=sqrt(c);
C(u,v)=a/(b*c);
end
end
end
S为实际图像,T为参考图像。
算法公式为: