繁体   English   中英

轮廓中的等间距点

[英]Equally spaced points in a contour

我有一组2D点(非有序)形成一个封闭的轮廓,我想将它们重新采样到14个等间距点。 它是图像上肾脏的轮廓。 有任何想法吗?

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

% 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段:

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 ...

假设您的轮廓由独立向量x和从属向量y定义。

您可以使用linspace获取重新采样的x向量:

new_x = linspace(min(x),max(x),14); %14 to get 14 equally spaced points

然后使用interp1在每个new_x点获取new_y值:

new_y = interp1(x,y,new_x);

有一些插值方法可供选择 - 默认是线性的。 有关详细信息,请参阅interp1帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM