Octave contourc格式 - >点坐标

时间:2017-06-27 12:00:04

标签: plot octave

octave以contourc格式保存轮廓数据,这对我来说有点特别。

是否有一些函数或脚本将这些数据转换为一系列数据 我可以绘制点坐标吗?仅限一个级别!

由于

1 个答案:

答案 0 :(得分:0)

处理一个级别的轮廓图格式的示例(在该级别可能有多个轮廓)。

A = zeros(5); A(2:4,2:4) = 1; A(3,3) = 0; % example image
ContourCFormat = contourc(A, 1); % one level only (but here happens to have two contours)
C = cell();
while ~isempty(ContourCFormat)
  N = ContourCFormat(2,1);
  C{end+1} = ContourCFormat(:, 2 : 1+N); 
  ContourCFormat(:, 1 : 1+N) = []; % Remove processed points
end

C =
{
  [1,1] =

     1.5000   2.0000   3.0000   4.0000   4.5000   4.5000   4.5000   4.0000   3.0000   2.0000   1.5000   1.5000   1.5000
     2.0000   1.5000   1.5000   1.5000   2.0000   3.0000   4.0000   4.5000   4.5000   4.5000   4.0000   3.0000   2.0000

  [1,2] =

     2.5000   3.0000   3.5000   3.0000   2.5000
     3.0000   2.5000   3.0000   3.5000   3.0000

}

说明:来自octave manual

  

返回值是一个2xn矩阵,包含以下格式的等高线:

[lev1, x1, x2, …, levn, x1, x2, ...
 len1, y1, y2, …, lenn, y1, y2, …]
     

其中轮廓线n的水平(高度)为levn,长度为lenn

因此,对于第一个轮廓,我们收集从2到N + 1的列,其中N由contourc输出的元素(2,1)给出。然后我们删除N + 1个元素并以相同的方式处理下一个轮廓,直到没有剩余的点为止。