2 ms·
Note that the 'Jump Flood Algorithm' is O(N log N) where N is the number of pixels. There is a better O(N) algorithm which can be parallelized over the number o
by johndough 2y ago
Note that the 'Jump Flood Algorithm' is O(N log N) where N is the number of pixels. There is a better O(N) algorithm which can be parallelized over the number of rows/columns of an image:
https://news.ycombinator.com/item?id=36809404 https://news.ycombinator.com/item?id=36809404
Unfortunately, it requires random access writes (compute shaders) if you want to run it on the GPU. But if CPU is fine, here are a few implementations:
JavaScript: https://parmanoir.com/distance/ https://parmanoir.com/distance/
C: https://github.com/983/df https://github.com/983/df
C++: https://github.com/opencv/opencv/blob/4.x/modules/imgproc/src/distransform.cpp https://github.com/opencv/opencv/blob/4.x/modules/imgproc/sr...
Python: https://github.com/pymatting/pymatting/blob/afd2dec073cb08b8119300feec18c179a9d436f3/pymatting/util/distance.py#L61 https://github.com/pymatting/pymatting/blob/afd2dec073cb08b8...
- pshc 2y agoDang, I implemented SDFs in 2023 around that time with jump flooding. Wish I had seen this version. Thanks for pointing it out!