clear all;
close all;
clc;
img=imread('Lena.bmp');
imshow(img);
title('原始图像');
img=double(img);
mask=double(imcrop);
subplot(1,2,1)
imshow(uint8(mask));
title('模板图像');
[a,b]=size(img);%原图大小
[m,n]=size(mask);%模板大小
for i=1:a-m %高
for j=1:b-n
r(i,j)=sum(sum(img(i:i+m-1,j:j+n-1).*mask))/sqrt(sum(sum(img(i:i+m-1,j:j+n-1)).^2)*sum(sum(ma sk.^2)));
end
end
[h,w]=find(r==max(max(r)));
subplot(1,2,2)
IMG=img(h:h+m-1,w:w+n-1);
imshow(uint8(IMG));
title('匹配图像');