function [output]=C_point(image,S,E)
% This function is used to get two basis points between fingers
% 采用轮廓跟踪法,得到两条曲线的坐标集,再通过求质心确定两个基准点
%
% Input Parameters:
%
% image --- 输入的图像
% S,E --- 起始点和终点的纵坐标
%
% Output Parameters:
%
% output --- 提取弧线所有点的重心坐标
%
function [output]=C_point(image,S,E)
n=0; % the number of points on the first curve
B_point=[];% the matrix which contain the coordination of the boundary
D_cw=[-1 1;0 1; 1 1; 1 0; 1 -1; 0 -1; -1 -1;-1 0;
-1 1;0 1; 1 1; 1 0; 1 -1; 0 -1; -1 -1;-1 0; ];
Temp=[S 2];% the begining point
temp=[];
for i=1:5
temp=Temp+D_cw(i,:); % 探寻起始点的八邻域邻点
if (image(temp(1),temp(2))==1) % 判断是否为边界点
Temp=temp;
break; % 找到第一个边界点,中止循环
end
B_point=[B_point;Temp]; % 将找到的点放到边界矩阵中
n=n+1; % 计数
end
begin=1;
while(~((Temp(1)==E)&&(Temp(2)==2))) % 若是结束点,则中止
for i=0:4
temp=Temp+D_cw(begin+i,:); % 探寻其八邻域内的点
if (n>3)
if (temp==B_point(n-1,:)) % 若找到下一点与前一点相同,则旋转180度
begin=4;
end
end
if (image(temp(1),temp(2))==1) % 如果为边界点,则把下一点作为当前点
Temp=temp;
break;
end
B_point=[B_point;Temp]; % 把找到的点放到边界矩阵中
n=n+1;
end
end
X_point=sum(B_point(:,1))/size(B_point,1);% 确定曲线点集的中心
Y_point=sum(B_point(:,2))/size(B_point,1);
output=[X_point Y_point];
小弟对matlab语言不熟,还请哪位大虾帮忙指点一下,万分感谢
我们马上要交作业了!!
[本帖最后由 edifiers2008 于 2008-12-2 16:53 编辑]