📄 testpipei_1.m
字号:
function testpipei_1()
%使用说明:此函数为单独使用,不具有交互性,因此必须在E盘下存在名为:P1010813.jpg的图像,
%在工作区中(此函数所在位置)必须存在名为afterCut.jpg的图像。afterCut.jpg最好是从
%P1010813.jpg的图像上剪裁下来的,P1010813.jpg图像不要太大,最好为500*500以内的,否则
%计算时间会很长
yuantu=imread('E:\P1010813.jpg');%加载原图象
pipeitu=imread('afterCut.jpg');%加载匹配图象
yuantu2gray=rgb2gray(yuantu);%将原图象转换为灰度图象
pipeitu2gray=rgb2gray(pipeitu);%将匹配图象转换为灰度图象
[pipei_height,pipei_width]=size(pipeitu2gray);%获取匹配图象的大小尺寸,其值为[长,宽],将匹配图象的长度值赋给pipei_width,将匹配图象的宽度值赋给pipei_lenth
[yuantu_height,yuantu_width]=size(yuantu2gray);%获取原图象的大小尺寸,其值为[长,宽],将原图象的长度值赋给pipei_width,将原图象的宽度值赋给pipei_lenth
imshow(yuantu);
hold on;
tic
for i=1:yuantu_height-pipei_height
for j=1:yuantu_width-pipei_width
temp_picture=imcrop(yuantu2gray,[j,i,pipei_width-1,pipei_height-1]);
r=corr2(temp_picture,pipeitu2gray);
if r>0.9
plot(j:j+pipei_width,i,'r');
plot(j:j+pipei_width,i+pipei_height,'r');
plot(j,i:i+pipei_height,'r');
plot(j+pipei_width,i:i+pipei_height,'r');
end
end
end
toc
figure;
imshow(pipeitu2gray);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -