資源簡介
運用模板匹配算法實現目標檢測,很好的圖像處理方法

代碼片段和文件信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?程序功能??:采用模板匹配算法實現對紅外圖像中的多機動目標的檢測工作
%?輸入變量??:
%???????????-?im_matched:??被檢測的紅外圖像
%???????????-?im_teplate:??模板?
%???????????-?T:??采樣間隔???????????
%???????????-?R:??相關函數
%???????????-?L:??存放檢測出的符合模板的目標(第k副圖,第len_tt個目標)
%???????????-?sigmaT:??模板像素
%???????????-?sigmaS:??被檢測圖像中模板覆蓋下的部分
%?作者?????:?何宇
%?日期?????:?2008-4-23
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear?all
for?k=1:54
str?=?sprintf(‘E:\\MATLAB7\\work\\Data\\data3\\28-%.0f.bmp‘k);
im_matched?=?imread(str);
im_template?=?imread(‘moban4.bmp‘);
%function?[maxHeightmaxWidthMaxR]?=?templateMatcher(im_matchedim_template)
%if??isrgb(im_matched)
????%im_matched?=?rgb2gray(im_matched);
%end
%if??isrgb(im_template)
???%?im_template?=?rgb2gray(im_template);
%end
dim_matched?=?double(im_matched);
dim_template?=?double(im_template);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%主程序
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%方差
?sigmaST?=?0.0;
?sigmaS?=?0.0;
?sigmaT?=?0.0;
%相似性測度
?double?R;
%最大相似性測度
?double?MaxR;
?MaxR?=?0.0;
%最大相似性出現位置
?maxWidth?=?0;
?maxHeight?=?0;
%計算sigmaT
[tempheighttempwidth]?=?size(im_template);
for?n?=1:tempheight
???for?m?=1:tempwidth
???????sigmaT?=?sigmaT?+?dim_template(nm)^2;
???end
end
sigmaT?=?sqrt(sigmaT);
%找到圖像中最大相似性的出現位置
[heightwidth]?=?size(im_matched);
len_tt?=?0;
for?j?=1:height-tempheight
????for?i?=1:width-tempwidth
????????sigmaST?=?0;
????????sigmaS?=?0;
????????for?n?=?1:tempheight
????????????for?m?=?1:tempwidth
?????????????sigmaS?=?sigmaS?+??dim_matched(j+ni+m)^2;
?????????????sigmaST?=?sigmaST?+?dim_template(nm)*dim_matched(j+ni+m);
?????????????end
????????end
????????
?????%計算相似性
?????sigmaS?=?sqrt(sigmaS);
?????R?=?sigmaST?/(sigmaS*sigmaT);
?????
?????%與最大相似性比較
?????if(R?>?MaxR)
?????????len_tt?=?len_tt+1;
?????????L(klen_tt).x?=?i;
?????????L(klen_tt).y?=?j;
?????????MaxR?=?R;
?????end
????end
end
figure
imshow(im_matched);hold?on;?plot([L(k:).x][L(k:).y]‘*r‘);
end
????????
?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2419??2008-04-22?09:21??mubiaojiance01.m
-----------?---------??----------?-----??----
?????????????????2419????????????????????1
- 上一篇:Writing A Compiler In Go
- 下一篇:一個銀行系統的作業。
評論
共有 條評論