Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 三维网格之间的Hausdorff距离_Python_Numpy_Scipy - Fatal编程技术网

Python 三维网格之间的Hausdorff距离

Python 三维网格之间的Hausdorff距离,python,numpy,scipy,Python,Numpy,Scipy,我有多个网格(numpy数组[Nk,Ny,Nx]),并希望使用Hausdorff距离作为这些网格的相似性度量。scipy中有几个模块(scipy.spatial.distance.cdist、scipy.spatial.distance.pdist),允许计算二维数组之间的欧几里德距离。现在要比较网格,我必须选择一些横截面(例如grid1[0,:]和grid2[0,:]),并相互比较。 是否可以直接计算三维网格之间的Hausdorff距离 我在这里是新手,但面临着同样的挑战,并试图在3D级别上直

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

我在这里是新手,但面临着同样的挑战,并试图在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日):

Recenty完成了此代码的微调版本。现在它被分成两部分

首先是在给定点周围抓取一个盒子,然后取所有半径。我认为这是一种减少检查所需点数的聪明方法。
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

这个问题()可能是相关的。结论似乎是没有scipy/numpy算法,如果速度很关键(这是2D),最好用c编写主算法。Farhawa,非常感谢!
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)