python - 使用 cKDTree 在一定距离内寻找最近的邻居并取这些邻居的平均值

标签 python nearest-neighbor point-clouds

我正在使用 python 脚本将两个大型(数百万个点)点云作为数组(“A”和“B”)读取。

我需要找到“A”中点的最近“B”邻居,但距离“A”中每个点 5 厘米以内。我还想对“A”中点的 5 厘米半径内的邻居进行平均。

有没有办法使用 cKTree 一次完成此操作,包括求平均值?

最佳答案

我不确定你想做什么,但如果我理解正确,你可以按照以下步骤操作:

# this are just random arrays for test
A = 20 * np.random.rand(1000, 3)
B = 20 * np.random.rand(1000, 3)

为每个点云计算一个 cKDTree

tree_A = cKDTree(A)
tree_B = cKDTree(B)

找出 A 中距离 B 中每个点至多 5 个单位的点:

# faster than loop + query_ball_point
neighbourhood = tree_B.query_ball_tree(tree_A, 5)

计算所有这些点组的平均值:

means = np.zeros_like(A)
for i in range(len(neighbourhood)):
    means[i] = A[neighbourhood[i]].mean(0)

关于python - 使用 cKDTree 在一定距离内寻找最近的邻居并取这些邻居的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40228212/

相关文章:

python - 如何使用上下文管理器来避免在 python 中使用 __del__?

python - 如何使用tensorflow在全连接层中恢复

python - 如何在不使用模型的情况下将 Django 集成到现有数据库中

algorithm - 二维快速k-最近邻搜索的数据结构和算法的合适选择

python - kd-tree 可以用点积构建吗?

javascript - 寻找最接近的可能坐标

algorithm - 给定点云和表面法线的表面重建

python - 这是来自 Python 的 `c` 函数吗?

c++ - 如何判断点云的单位是什么?

image-processing - 将 3D 图像数据分析为 2D