?? testpipei_2.asv
字號:
function testpipei_2()%基于圖象灰度的快速匹配算法
%使用說明:此函數為單獨使用,不具有交互性,因此必須在E盤下存在名為:P1010813.jpg的圖像,
%在工作區中(此函數所在位置)必須存在名為afterCut.jpg的圖像。afterCut.jpg最好是從
%P1010813.jpg的圖像上剪裁下來的,P1010813.jpg
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
temp_min=min([pipei_height,pipei_width]);
temp_min=fix(temp_min/20);
geshu=(temp_min-2)^2;%匹配圖R塊的個數
fprintf('%d',geshu);
for t=1:temp_min-2%去掉外圍的一圈
for s=1:temp_min-2%取順時針為正方向
temp_pipeitu(t,s)=bin2dec(gettezheng(t,s,pipeitu2gray));
end;
end;
imshow(yuantu);
hold on;
tic
for i=1:yuantu_height-temp_min*20
for j=1:yuantu_width-temp_min*20
temp_picture=imcrop(yuantu2gray,[j,i,pipei_width-1,pipei_height-1]);
% r=corr2(temp_picture,pipeitu2gray);
r=0;
for t=1:temp_min-2%去掉外圍的一圈
for s=1:temp_min-2%取順時針為正方向
temp_pipeitu_te=temp_pipeitu(t,s);
temp_yuantu_te=bin2dec(gettezheng(t,s,temp_picture));
if temp_pipeitu_te==temp_yuantu_te
r=r+1;
else
break;
end;
end;
if r==0
break;
end;
end;
if r>=fix(geshu*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(pipeitu);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -