Created
May 21, 2020 09:13
-
-
Save marmakoide/cd4598759af83f368b7023504510180e to your computer and use it in GitHub Desktop.
SIMD implementation of 2d reverse euclidean distance. See "Optimal Separable Algorithms to Compute the Reverse Euclidean Distance Transformation and Discrete Medial Axis in Arbitrary Dimension" D. Coeurjolly et al.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
def reverse_euclidean_distance_transform(F): | |
ret = numpy.empty_like(F, dtype = int) | |
def get_parabola_matrix(N): | |
X = numpy.arange(N, dtype = int) | |
G = numpy.empty((N, N), dtype = int) | |
G[:] = X | |
G -= X[:, None] | |
G *= G | |
G *= -1 | |
return G | |
# Horizontal pass | |
G = get_parabola_matrix(F.shape[1]) | |
for i in range(F.shape[0]): | |
numpy.amax(G + F[i][:, None], axis = 0, out = ret[i, :]) | |
# Vertical pass | |
G = get_parabola_matrix(F.shape[0]) | |
for i in range(F.shape[1]): | |
numpy.amax(G + ret[:,i][:, None], axis = 0, out = ret[:, i]) | |
# Job done | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment