3D网格之间的Hausdorff距离 [英] Hausdorff distance between 3D grids

查看:244
本文介绍了3D网格之间的Hausdorff距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have multiple grids (numpy arrays [Nk,Ny,Nx]) and would like to use Hausdorff distance as a metric of similarity of these grids. There are several modules in scipy (scipy.spatial.distance.cdist,scipy.spatial.distance.pdist) which allow to calculate Euclidean distance between 2D arrays. Now to compare grids I have to choose some cross-section (e.g. grid1[0,:] & grid2[0,:]) and compare it between each other. Is it possible to calculate Hausdorff distance between 3D grids directly?

推荐答案

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

I am newby here, but faced with the same challenge and tried to attack it directly on a 3D level.

这是我执行的功能:

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,其余输入可直接使用.

The input needs to be numpy.array, but the rest is working directly.

我有8000个vs.5000个3D点,它运行了几分钟,但最终到达了您要寻找的距离.

I have 8000 vs. 5000 3D points and this runs for several minutes, but at the end it gets to the distance you are looking for.

这是检查两个点之间的距离,而不是两个曲线的距离. (都不是网格).

This is however checking the distance between two points, not neccesarily the distance of two curves. (neither mesh).

修改(2015年11月26日):

Recenty完成了此代码的微调版本.现在将其分为两部分.

Recenty finished the fine-tuned version of this code. Now it is splitted into two part.

首先要注意在给定点周围抓住一个盒子,并取走所有半径.我认为这是减少检查所需点数的明智方法.

First is taking care of grabbing a box around a given point and taking all the radius. I consider this as a smart way to reduce the number of points required to check.

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

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

And the other code for the distance calculation:

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)

这篇关于3D网格之间的Hausdorff距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆