資源簡介
用matlab實現圖像的模板匹配,簡單易用,有實例。

代碼片段和文件信息
%?Target?Recongition
%?This?program?detects?a?target?in?a?given?image?and?focuses?on?it
%?Programmed?By:?Mina?Ayman?Makar
%?On?2/2/2004
%?Part(1)?:?Entering?the?image?for?MATLAB
fprintf(‘\n?This?program?detects?a?target?in?an?image‘)
fprintf(‘\n?Entering?the?image?for?MATLAB...‘)
fprintf(‘\n?Save?the?image?or?its?copy?in?MATLAB?working?Directory‘)
imagname?=?input(‘\n?Enter?the?name?of?the?image?file?(filename.ext)?:?‘‘s‘);
w?=?imread(imagname);
w?=?im2double(w);
sizw?=?size(w);
figure
imshow(w)
title(‘Input?Image‘)
pause(3.5);
close;
fprintf(‘\n?Entering?the?target?image?for?MATLAB...‘)
fprintf(‘\n?Save?the?target?image?or?its?copy?in?MATLAB?working?Directory‘)
tarname?=?input(‘\n?Enter?the?name?of?the?target?image?file?(filename.ext)?:?‘‘s‘);
t?=?imread(tarname);
t?=?im2double(t);
sizt?=?size(t);
figure
imshow(t)
title(‘Target?Image‘)
pause(3.5);
close;
ww?=?rgb2gray(w);
tt?=?rgb2gray(t);
tedge?=?edge(tt);
wedge?=?edge(ww);
out?=?filter2(tedgewedge);
o?=?max(max(out));
output?=?(1/o)*out;
pixel?=?find(output?==?1);
pcolumn?=?fix(pixel?/?sizw(1));
prow?=?mod(pixelsizw(1));
rdis?=?fix(sizt(1)/2);
cdis?=?fix(sizt(2)/2);
cmin?=?pcolumn?-?cdis;
cmax?=?pcolumn?+?cdis;
rmin?=?prow?-?rdis;
rmax?=?prow?+?rdis;
c?=?[cmin?cmin?cmax?cmax];
r?=?[rmin?rmax?rmax?rmin];
m?=?roipoly(wwcr);
m?=?im2double(m);
m?=?0.5?*?(m?+?1);
mask(::1)?=?m;
mask(::2)?=?m;
mask(::3)?=?m;
final?=?mask?.*?w;
figure
imshow(final)
title(‘Result?Image‘)
pause(3.5);
close;
subplot(121)
imshow(w)
title(‘Input?Image‘)
subplot(122)
imshow(final)
title(‘Result?Image‘)
sav?=?input(‘\n?Do?you?like?to?SAVE?Result?Image??(y/n)?:?‘‘s‘);
if?(sav?==?‘y‘)
????fprintf(‘\n?You?choose?to?SAVE?the?Result?Image‘)
????naming?=?input(‘\n?Type?the?name?of?the?new?image?file?(filename.ext)?:?‘‘s‘);
????fprintf(‘\n?Saving?...‘)
????imwrite(finalnaming);
????fprintf(‘\n?The?new?file?is?called?%s?and?it?is?saved?in?MATLAB?working?Directory‘naming)
else
????fprintf(‘\n?You?choose?NOT?to?SAVE?the?Result?Image‘)
end
clear
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6629??2007-06-06?10:34??98240713Cross-Correlation-Target-Image-Detection\image1.jpg
?????文件????????903??2007-06-18?14:50??98240713Cross-Correlation-Target-Image-Detection\image2.JPG
?????文件???????1009??2008-05-22?13:40??98240713Cross-Correlation-Target-Image-Detection\K.JPG
?????文件???????9516??2008-05-22?13:40??98240713Cross-Correlation-Target-Image-Detection\letters.JPG
?????文件???????7334??2010-09-14?15:31??98240713Cross-Correlation-Target-Image-Detection\Result.jpg
?????文件???????2091??2008-01-27?22:28??98240713Cross-Correlation-Target-Image-Detection\target.m
?????目錄??????????0??2011-03-21?17:09??98240713Cross-Correlation-Target-Image-Detection
-----------?---------??----------?-----??----
????????????????27482????????????????????7
- 上一篇:光伏MPPT模型
- 下一篇:圖像分割的多種算法MATLAB代碼
評論
共有 條評論