資源簡介
自己編寫的matlab程序
實現數字圖像的模板匹配和相關算法,以及亞像素算法
壓縮包中含源程序,實例圖片和模板,以及模板生成算法。
使用方法:
1、設定路徑
2、打開threshold,F5
有問題歡迎提問。

代碼片段和文件信息
clc
format?compact
more?off
%load?samples/coords/syntcds
%load?samples/coords/realcds
%addpath?solvopt
addpath?F:\
addpath?F:\20091201\2\
echo?on
%
%?press?enter?to?start?the?calibration?with?synthetic?data
pause
tic
path(‘F:\20091201\1\‘path)
b=load(‘模板.txt‘);
%讀取圖像
image3=imread(‘image.bmp‘);
image2=image3;
K=image3;
%K=double(image3(::2));
%圖像灰度值的閾值隨著圖像質量改變
K_threshold=graythresh(K);
BW?=?im2bw(double(K)./255K_threshold);
%treshold?and?erode?dilate?etc.?operations.
%J=find(K<70);
%K(J)=0;
%J=find(K>=70);
%K(J)=255;
%image=image3(::2);
%imshow(K)
%Mask?=?strel(‘rectangle‘[3?3]);
%K_erode?=?imerode(BWMask);
%K_dilate=imdilate(K_erodeMask);
%J=find(K_dilate==1);
%end?open?operation.
J=find(BW==1);
length=size(J);
Gray_point=[floor(J/2048)rem(J2048)];
Gray_xy=round(mean(Gray_point));
Gray_d=round(3*(Gray_xy(11)-Gray_point(11))/4);
%Gray_d=3*(Gray_xy(11)-Gray_point(11))/4;
%yc=Gray_xy(11)-Gray_d;
%xc=Gray_xy(12);
%yc1=Gray_xy(11);
%xc1=Gray_xy(12)-Gray_d;
yc1=Gray_xy(11)-Gray_d;
xc1=Gray_xy(12);
yc=Gray_xy(11);
xc=Gray_xy(12)-Gray_d;
yc3=Gray_xy(11);
xc3=Gray_xy(12)+Gray_d;
yc2=Gray_xy(11)+Gray_d;
xc2=Gray_xy(12);
[x_suby_submaxcor]?=?thresholdmax(?xcyc?Gray_dbimage3);?
[x_sub1y_sub1maxcor1]?=?thresholdmax(?xc1yc1Gray_dbimage3);
[x_sub2y_sub2maxcor2]?=?thresholdmax(?xc2yc2Gray_dbimage3?);
[x_sub3y_sub3maxcor3]?=?thresholdmax(?xc3yc3Gray_dbimage3?);
pix=[y_subx_submaxcor
????y_sub1x_sub1maxcor1
????y_sub2x_sub2maxcor2
????y_sub3x_sub3maxcor3];
%Below?is?the?function?of?showing?the?point?in?the?picture?and?save?the
%picture.
pix_int=round(pix);
xcenter_sub=(pix(11)+pix(21)+pix(31)+pix(41))/4
ycenter_sub=(pix(12)+pix(22)+pix(32)+pix(42))/4
xcenter_pix=floor((pix(11)+pix(21)+pix(31)+pix(41))/4)
ycenter_pix=floor((pix(12)+pix(22)+pix(32)+pix(42))/4)
image2(xcenter_pix+1ycenter_pix+1)=255;
image2(floor(x_sub)+1floor(y_sub)+1)=0;
image2(floor(x_sub1)+1floor(y_sub1)+1)=0;
image2(floor(x_sub2)+1floor(y_sub2)+1)=0;
image2(floor(x_sub3)+1floor(y_sub3)+1)=0;
image_show=double(image2(ycenter_pix-2*Gray_d:ycenter_pix+2*Gray_d-1xcenter_pix-2*Gray_d:xcenter_pix+2*Gray_d-1));
figure(4)
imshow(image_show[0255]);
format?long?g
save(‘sub_pix.txt‘‘pix‘‘-ASCII‘‘-double‘);
%im3=uint8(image2);
%imwrite(im3‘image.bmp‘);
im=uint8(image_show);
imwrite(im‘sub_image.bmp‘);
toc
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3800??2009-09-10?13:28??模板.txt
?????文件???????2426??2010-12-13?10:45??threshold.m
?????文件???????2897??2009-12-03?15:46??thresholdmax.m
?????文件????5014582??2009-12-01?15:35??image.bmp
?????文件???????1500??2009-12-07?11:25??模板生成Matlab.txt
-----------?---------??----------?-----??----
??????????????5025205????????????????????5
評論
共有 條評論