将轮廓转换为点集

Convert Contours into Set of Points

我有一个形状(花边界)的轮廓,是我在 Octave 中使用轮廓函数得到的(附在下面)。

我想将其转换为表示形状的点集,并将展开形状的函数拟合为极坐标形式的角度的线性函数。我正在 MATLAB 中尝试,但在 python 中回答也可以。

主要关心的是如何将该轮廓转换为一组点。

附上下面的轮廓图,

Contour image

请帮帮我!

你的问题很含糊,所以我在这里做了很多假设,但这是我从你的问题中了解到的:

  1. 您有一个“绘图 window”,显示等高线图。
  2. 就你而言,你无法控制这个过程,你不知道等高线图是如何产生的,从什么数据,没有办法调用其他东西而不是等高线图你的数据。
  3. 您只想直接从图形对象中提取所需轮廓的点。

这是一个如何做到这一点的例子。我没有你的情节,所以我将使用内置的“峰”功能来生成轮廓。

% Generate a surface plot
  peaks;

% Grab the 'peaks' graphical object, which here is the only 'child' object of the main 'axes' object
  PeaksObj = get( gca, 'children' );

% Grab the X, Y, and Z data that was used to generate this surface plot
  X = get( PeaksObj, 'xdata' );
  Y = get( PeaksObj, 'ydata' );
  Z = get( PeaksObj, 'zdata' );

% Generate our example contour plot
  contour( X, Y, Z );

太好了,现在我们可以使用等高线图了。假设我们不知道这是如何生成的。

在octave中,一个'contour plot'其实就是一组单独的线图。首先我们需要从当前轴对象中获取 'group object':

% Grab the contour 'group' object from the current axes object
  ContourGrp = get( gca, 'children' );

% The contour 'group' object should have children, which are individual contours.
  Contours = get( ContourGrp, 'children' );

此时,您有一组单独的线图,对应于单独的等高线。您需要确定这些轮廓中的哪一个是您感兴趣的。以交互方式执行此操作的一种方法是 'fill and unfill' 每个轮廓,一个接一个,然后找到您感兴趣的轮廓。例如,对“Contours”数组的每个元素执行此操作(即,如果有 'k' 个元素,将 k 更改为取值从 1 到有多少个元素):

% Experiment to find the contour of interest
  k = 1
  set( Contours(k), 'facecolor', 'r'    );
  set( Contours(k), 'facecolor', 'none' );

假设您想要的轮廓是 k = 5。现在我们可以获取构成该轮廓线的 X 和 Y 数据:

% Get the X and Y data from the right contour
  X = get( Contours(k), 'xdata' );
  Y = get( Contours(k), 'ydata' );

% Plot X against Y to confirm
  plot( X, Y );

恭喜。现在您有了 X Y 点,您可以从中计算质心并导出半径和角度以传递到极坐标图中。