轮廓中等距的点

use*_*988 4 matlab interpolation image-processing points contour

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

cha*_*pjc 5

一种直观的方法 (IMO) 是为x和两者创建一个自变量y。以弧长为基础,并对其进行插值。

% 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);
Run Code Online (Sandbox Code Playgroud)

现在您有了一个自变量,您可以进行插值来创建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)=[];
Run Code Online (Sandbox Code Playgroud)

尝试使用imfreehand

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