且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

轮廓中等距的点

更新时间:2022-01-09 22:51:23

一种直观的方法(IMO)是为xy创建一个自变量.以弧长为基础,并在其上进行插值.

One intuitive approach (IMO) is to create an independent variable for both x and y. Base it on arc length, and interpolate on it.

% close the contour, temporarily
xc = [x(:); x(1)];
yc = [y(:); y(1)];

% current spacing may not be equally spaced
dx = diff(xc);
dy = diff(yc);

% distances between consecutive coordiates
dS = sqrt(dx.^2+dy.^2);
dS = [0; dS];     % including start point

% arc length, going along (around) snake
d = cumsum(dS);  % here is your independent variable
perim = d(end);

现在您有了一个自变量,可以进行插值以创建N段:

Now you have an independent variable and you can interpolate to create N segments:

N = 14;
ds = perim / N;
dSi = ds*(0:N).'; %' your NEW independent variable, equally spaced

dSi(end) = dSi(end)-.005; % appease interp1

xi = interp1(d,xc,dSi);
yi = interp1(d,yc,dSi);

xi(end)=[]; yi(end)=[];

使用imfreehand尝试:

figure, imshow('cameraman.tif');
h = imfreehand(gca);
xy = h.getPosition; x = xy(:,1); y = xy(:,2);
% run the above solution ...