【问题标题】:Python: Interpolate lines and get the Euclidean DistancePython:插值线并获得欧几里得距离
【发布时间】:2018-07-19 15:05:18
【问题描述】:

我有以下问题。我有一条线的点的坐标。现在我想连接它们或对它们进行插值,以便我在房间中有一条连续的线并计算到其余框坐标的欧几里得距离,例如(21,41,91)形状的 numpy 数组(即不应该是 scipy、skimage 等的问题)。

所以我想做这样的事情,但在 3D 中:

Distance Transformation

Distances on grid

所以线体素将得到零,所有其余的坐标都是零。我不想要一条线的点的距离或线的总长度

这是点如何在房间中分布的可视化

Spreaded points in room

例如,这里是其中一行的 numpy 数组中的坐标。它们按正确的顺序排列:

import numpy as np

line1 = np.array([[ 14,11,35],
 [ 13,14,37],
 [ 11,17,38],
 [ 11,19,41],
 [ 12,21,43],
 [ 15,24,46],
 [ 18,27,46],
 [ 19,30,45],
 [ 20,33,45],
 [ 21,36,46],
 [ 22,37,47],
 [ 24,37,47],
 [ 23,40,49],
 [ 24,42,51],
 [ 21,44,50],
 [ 19,46,48],
 [ 18,47,45]])

【问题讨论】:

标签: python numpy matplotlib scipy interpolation


【解决方案1】:

IIUC:

In [108]: from mpl_toolkits.mplot3d import Axes3D

In [109]: fig = plt.figure()
     ...: ax = fig.add_subplot(111, projection='3d')


In [112]: ax.plot(line1[:, 0], line1[:, 1], line1[:, 2])
Out[112]: [<mpl_toolkits.mplot3d.art3d.Line3D at 0x13913a20>]

结果:

更新:将其保存为 TIFF:

In [128]: from PIL import Image

In [129]: from io import BytesIO

In [130]: buf = BytesIO()

In [131]: fig = plt.figure()
     ...: ax = fig.add_subplot(111, projection='3d')
     ...:

In [132]: ax.plot(line1[:, 0], line1[:, 1], line1[:, 2])
Out[132]: [<mpl_toolkits.mplot3d.art3d.Line3D at 0x14cdccc0>]

In [133]: fig.savefig(buf)

In [134]: Image.open(buf).save(r'd:/temp/out.tiff')

【讨论】:

  • 很好,但是否也可以获取适合特定网格的插值线的坐标,每个维度中的 linspaces 1 或将该线保存在 3D tiff 中?
  • 好的,这是 matplotlib 绘图的图片,但我需要一个包含线条的所有插值坐标的数组或一个只有后框中的线条的 3d tiff
猜你喜欢
  • 2013-03-02
  • 2010-12-15
  • 1970-01-01
  • 1970-01-01
  • 2015-07-15
  • 2014-02-04
  • 1970-01-01
相关资源
最近更新 更多