def direction_map(dmap: DistanceMap):
r"""Computes normalized gradient of distance map. Not defined when length of
the gradient is zero.
.. math::
\hat{\mathbf{e}}_{S} = -\frac{\nabla S(\mathbf{x})}{\| \nabla S(\mathbf{x}) \|}
Args:
dmap (numpy.ndarray):
Distance map.
Returns:
DirectionMap: Direction map.
"""
u, v = np.gradient(dmap)
l = np.hypot(u, v)
# Avoids zero division
l[l == 0] = np.nan
# Flip order from (row, col) to (x, y)
return v / l, u / l
# Potentials
评论列表
文章目录