Python:插值线并获得欧氏距离

w3nuxt5m  于 2023-03-16  发布在  Python
关注(0)|答案(1)|浏览(118)

我有以下问题:我有一条线上各点的坐标,现在我想把它们连接起来或进行插值,这样我在房间里就有了一条连续的线,并计算到其余方框坐标的欧氏距离,例如,方框坐标可以是一个(21,41,91)形的numpy数组(这不应该是scipy、skimage等的问题)。
所以我想用3D的方式做一些类似的事情:
Distance Transformation
Distances on grid
所以线体素的值为0,其余的坐标值为1,我不需要线的点的距离,或者线的总长度
这是这些点在房间中分布的可视化视图
Spread points in room

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

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]])
mwkjh3gx

mwkjh3gx1#

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')

相关问题