轮廓中等距的点 [英] Equally spaced points in a contour

查看:92
本文介绍了轮廓中等距的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组2D点(无序)形成一个闭合轮廓,我想将它们重新采样到14个等距点.它是图像上肾脏的轮廓.有什么想法吗?

I have a set of 2D points (not ordered) forming a closed contour, and I would like to resample them to 14 equally spaced points. It is a contour of a kidney on an image. Any ideas?

推荐答案

一种直观的方法(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 ...

这篇关于轮廓中等距的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆