轮廓中的等间距点

时间:2014-12-11 18:21:08

标签: matlab image-processing interpolation contour points

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

假设您的轮廓由独立向量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帮助。