python三维网格图_python-3D网格之间的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个vs.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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值