我首先初始化了一些点,在它们之间进行了插值,然后统一对点进行重采样。结果如下所示,我现在有一组100分。
function P = MakeContourClockwise2D(P)
% Area inside contour
O = [P; P(1:2,:)];
area = 0.5*sum((O((1:size(P,1))+1,1) .* (O((1:size(P,1))+2,2) - O((1:size(P,1)),2))));
% If the area inside the contour is positive, change from counter-clockwise to clockwise
if(area>0), P=P(end:-1:1,:); end
function K = InterpolateContourPoints2D(P,nPoints)
% Interpolate points inbetween
O(:,1) = interp([P(end-3:end,1);P(:,1);P(:,1);P(1:4,1)],10);
O(:,2) = interp([P(end-3:end,2);P(:,2);P(:,2);P(1:4,2)],10);
O = O(41:end-39,:);
% Calculate distance between points
dis = [0;cumsum(sqrt(sum((O(2:end,:)-O(1:end-1,:)).^2,2)))];
% Resample to make uniform points
K(:,1) = interp1(dis,O(:,1),linspace(0,dis(end),nPoints*2));
K(:,2) = interp1(dis,O(:,2),linspace(0,dis(end),nPoints*2));
K = K(round(end/4):round(end/4)+nPoints-1,:);
如何找到轮廓的法向矢量场和切线矢量场?
x = [163 166 207 248 210];
y = [182 233 251 205 169];
P = [x(:) y(:)];
P = MakeContourClockwise2D(P);
P = InterpolateContourPoints2D(P,100);
统一采样点的图像: