【问题标题】:Hausdorff distance between 3D grids3D网格之间的豪斯多夫距离
【发布时间】:2016-10-04 16:56:22
【问题描述】:

我有多个网格(numpy 数组 [Nk,Ny,Nx])并且想使用 Hausdorff 距离作为这些网格相似度的度量。 scipy 中有几个模块(scipy.spatial.distance.cdist,scipy.spatial.distance.pdist)允许计算二维数组之间的欧几里得距离。现在要比较网格,我必须选择一些横截面(例如 grid1[0,:] & grid2[0,:])并相互比较。 是否可以直接计算 3D 网格之间的 Hausdorff 距离?

【问题讨论】:

  • 这个问题 (stackoverflow.com/questions/13692801/…) 可能是相关的。结论似乎是没有 scipy/numpy 算法,如果速度很关键(那是 2D),最好用 c 编写主要算法。
  • 法哈瓦,非常感谢!

标签: python numpy scipy


【解决方案1】:

我是这里的新手,但面临同样的挑战,并试图直接在 3D 级别上对其进行攻击。

所以这是我做的功能:

def Hausdorff_dist(vol_a,vol_b):
dist_lst = []
for idx in range(len(vol_a)):
    dist_min = 1000.0        
    for idx2 in range(len(vol_b)):
        dist= np.linalg.norm(vol_a[idx]-vol_b[idx2])
        if dist_min > dist:
            dist_min = dist
    dist_lst.append(dist_min)
return np.max(dist_lst)

输入需要是numpy.array,但其余的直接工作。

我有 8000 和 5000 个 3D 点,这会运行几分钟,但最后会到达您要寻找的距离。

然而,这是检查两点之间的距离,而不是检查两条曲线的距离。 (没有网格)。

编辑(2015 年 11 月 26 日):

最近完成了这段代码的微调版本。现在它被分成两部分。

首先是在给定点周围抓取一个盒子并占据所有半径。我认为这是减少检查点数的明智方法。

def bbox(array, point, radius):
    a = array[np.where(np.logical_and(array[:, 0] >= point[0] - radius, array[:, 0] <= point[0] + radius))]
    b = a[np.where(np.logical_and(a[:, 1] >= point[1] - radius, a[:, 1] <= point[1] + radius))]
    c = b[np.where(np.logical_and(b[:, 2] >= point[2] - radius, b[:, 2] <= point[2] + radius))]
    return c

以及距离计算的其他代码:

def hausdorff(surface_a, surface_b):

    # Taking two arrays as input file, the function is searching for the Hausdorff distane of "surface_a" to "surface_b"
    dists = []

    l = len(surface_a)

    for i in xrange(l):

        # walking through all the points of surface_a
        dist_min = 1000.0
        radius = 0
        b_mod = np.empty(shape=(0, 0, 0))

        # increasing the cube size around the point until the cube contains at least 1 point
        while b_mod.shape[0] == 0:
            b_mod = bbox(surface_b, surface_a[i], radius)
            radius += 1

        # to avoid getting false result (point is close to the edge, but along an axis another one is closer),
        # increasing the size of the cube
        b_mod = bbox(surface_b, surface_a[i], radius * math.sqrt(3))

        for j in range(len(b_mod)):
            # walking through the small number of points to find the minimum distance
            dist = np.linalg.norm(surface_a[i] - b_mod[j])
            if dist_min > dist:
                dist_min = dist

        dists.append(dist_min)

    return np.max(dists)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 2020-03-10
    • 2019-04-03
    • 1970-01-01
    相关资源
    最近更新 更多