简体   繁体   English

如何根据点坐标和所需的 bin 网格大小有效地 bin 3D 点云数据

[英]How can I efficiently bin 3D point cloud data based on point coordinates and desired bin grid size

I have a large point cloud in open3D and I want to basically make a 3D grid and bin the points based on which cube they are in. Other have called it "binning in 3D space."我在 open3D 中有一个大点云,我想基本上制作一个 3D 网格并根据它们所在的立方体对点进行分类。其他人称之为“在 3D 空间中进行分类”。

Example image with grids only in one direction (I want to split into 3D volumes)仅在一个方向上带有网格的示例图像(我想拆分为 3D 卷)

Better Image of what I'm trying to do更好地了解我正在尝试做的事情

Example:例子:

import numpy as np

A = np.array([[ 0, -1, 10],
 [ 1, -2 ,11],
 [ 2, -3 ,12],
 [ 3, -4 ,13],
 [ 4, -5 ,14],
 [ 5, -6 ,15],
 [ 6, -7 ,16],
 [ 7, -8 ,17],
 [ 8, -9 ,18]])

#point 1: X,Y,Z
#point 2: X,Y,Z

print(A)

X_segments = np.linspace(0,8,3) #plane at beginning, middle and end - this creates 2 sections where data can be
Y_segments = np.linspace(-9,-1,3)
Z_segments = np.linspace(10,18,3)

#all of these combined form 4 cuboids where data can be 
#its also possible for the data to be outside these cuboids but we can ignore that

bin1 =  A where A[0,:] is > X_segments [0] and < X_segments[1]
    and A where A[1,:] is > Y_segments [0] and < Y_segments[1] 
    and A where A[2,:] is > Z_segments [0] and < Z_segments[1] 

bin2 =  A where A[0,:] is > X_segments [1] and < X_segments[2]
    and A where A[1,:] is > Y_segments [0] and < Y_segments[1] 
    and A where A[2,:] is > Z_segments [0] and < Z_segments[1] 

bin3 =  A where A[0,:] is > X_segments [1] and < X_segments[2]
    and A where A[1,:] is > Y_segments [1] and < Y_segments[2] 
    and A where A[2,:] is > Z_segments [0] and < Z_segments[1] 

bin4 =  A where A[0,:] is > X_segments [1] and < X_segments[2]
    and A where A[1,:] is > Y_segments [1] and < Y_segments[2] 
    and A where A[2,:] is > Z_segments [1] and < Z_segments[2]  

Thanks yall!谢谢你们!

You can try the following:您可以尝试以下方法:

import numpy as np

A = np.array([[ 0, -1, 10],
              [ 1, -2 ,11],
              [ 2, -3 ,12],
              [ 3, -4 ,13],
              [ 4, -5 ,14],
              [ 5, -6 ,15],
              [ 6, -7 ,16],
              [ 7, -8 ,17],
              [ 8, -9 ,18]])

X_segments = np.linspace(0,8,3)
Y_segments = np.linspace(-9,-1,3)
Z_segments = np.linspace(10,18,3)

edges = [X_segments, Y_segments, Z_segments]

print(edges) # just to show edges of the bins

We get:我们得到:

[[ 0.  4.  8.]
 [-9. -5. -1.]
 [10. 14. 18.]]

Next, apply np.digitize along each coordinate axis:接下来,沿每个坐标轴应用np.digitize

coords = np.vstack([np.digitize(A.T[i], b, right=True) for i, b in enumerate(edges)]).T
print(coords)

This gives:这给出了:

[[0 2 0]
 [1 2 1]
 [1 2 1]
 [1 2 1]
 [1 1 1]
 [2 1 2]
 [2 1 2]
 [2 1 2]
 [2 0 2]]

Rows of this array describe positions of the corresponding rows of A in the grid of bins.该数组的行描述了A的相应行在 bin 网格中的位置。 For example, the second row [1, 2, 1] indicates that the second row of A , ie [1, -2, 11] is in the first bin along the X-axis (since 0 < 1 <= 4 ), in the second bin along the Y-axis (since -5 < -2 <= -1 ), and in the first bin along the Z-axis (since 10 < 11 <= 14 ).例如,第二行[1, 2, 1]表示A的第二行,即[1, -2, 11]在沿 X 轴的第一个 bin 中(因为0 < 1 <= 4 ),在沿 Y 轴的第二个 bin 中(因为-5 < -2 <= -1 ),在沿 Z 轴的第一个 bin 中(因为10 < 11 <= 14 )。 Then you can pick elements belonging to each cuboid:然后你可以选择属于每个长方体的元素:

# select rows of A that are in the cuboid with coordinates [1, 2, 1]
A[np.all(coords == [1, 2, 1], axis=1)] 

This gives:这给出了:

array([[ 1, -2, 11],
       [ 2, -3, 12],
       [ 3, -4, 13]])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM