資源簡介
利用hausdorff距離變換實現的圖像模板匹配(matlab),

代碼片段和文件信息
clear?all;clc;
tic
Img_Template?=?imread(‘Template_1.jpg‘);
Img_Scene?=?imread(‘Scene.jpg‘);
if?size(Img_Template3)==3
????Img_Template=rgb2gray(Img_Template);
end
if?size(Img_Scene3)==3
????Img_Scene=rgb2gray(Img_Scene);
end
T?=?double(Img_Template);
S?=?double(Img_Scene);
T_Edge?=?edge(Img_Template‘sobel‘);
S_Edge?=?edge(Img_Scene‘sobel‘);
[Row_T?Column_T]?=?size(T_Edge);
[Row_S?Column_S]?=?size(S_Edge);
DT_S?=?bwdist(S_Edge‘cityblock‘);
index?=?find(T_Edge);
for?r?=?1:Row_S-Row_T+1
????for?c?=?1:Column_S-Column_T+1
????????Block?=?DT_S(r:r+Row_T-1c:c+Column_T-1);
????????D(rc)?=?max(Block(index));
????end
end
[val?ind]?=?sort(D(:));
[Pos_r?Pos_c]?=?ind2sub(size(D)ind(1));%length(D(:))
Top_r?=?Pos_r;
Down_r?=?Pos_r?+?Column_T-1;
Left_c?=?Pos_c;
Right_c?=?Pos_c?+?Row_T-1;
x?=?Left_c?-?1;
y?=?Row_S?-?Down_r+1;
figure;
subplot(121);
imshow(Img_Scene);
rectangle(‘Position‘[Pos_cPos_rColumn_TRow_T]‘EdgeColor‘‘r‘);
title([‘目標坐標?[x?y]=?[‘?num2str(x)?‘‘?num2str(y)?‘]‘]);
subplot(122);
imshow(Img_Template);
title(‘模板‘);
toc
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????1099??2019-01-11?19:23??aaa.m
?????文件????????1015??2012-12-21?21:31??corr_match.m
?????文件????????1026??2019-01-10?15:22??dt_hausdorff.m
?????文件????????2194??2019-01-11?20:46??Hausdorff_Match.m
?????文件?????????737??2019-01-11?20:45??Matching.m
?????文件????????9049??2011-12-16?17:20??Scene.jpg
?????文件????????9731??2011-12-16?17:39??Template_1.jpg
?????文件????????2277??2011-12-17?17:32??Template_2.jpg
- 上一篇:獲取一張圖片上的坐標點
- 下一篇:基于EKF二階RC模型電池Soc預測仿真
評論
共有 條評論