yuantu=imread('a1.bmp');
pipeitu=imread('a2.bmp'); %读入原图和配准图
x=rgb2gray(yuantu);
y=rgb2gray(pipeitu); %把原图和配图变为灰度
[yuantu_height,yuantu_width]=size(x);
[pipei_height,pipei_width]=size(y); %进一步获取图片尺寸
imshow(x); hold on;
figure;
imshow(y); %显示预处理后的原图和配图
figure(3);
imshow(x);hold on;
t0=cputime;
hbar = waitbar(0,'Image matching');
tic;%时间计算开始
for i=1:yuantu_height-pipei_height
for j=1:yuantu_width-pipei_width
temp_picture=imcrop(x,[j,i,pipei_width-1,pipei_height-1]);
r=corr2(temp_picture,y); %对预处理后的原图和配图进行循环比较得到匹配区域
if r>0.85
plot(j:j+pipei_width,i,'r');hold on;
plot(j:j+pipei_width,i+pipei_height,'r');hold on;
plot(j,i:i+pipei_height,'r');hold on;
plot(j+pipei_width,i:i+pipei_height,'r');hold on; %标记出匹配区域
end
end
end
%匹配结束,计算总时间
t2=toc;
close(hbar);
t1=cputime-t0