Distance Transforms
DistanceTransforms.jl and distance_transforms provides efficient, GPU-accelerated, distance transform operations for arrays in both Julia and Python. Distance transforms are essential in computer vision, image processing, and machine learning tasks.

Features
| Feature | Description |
|---|---|
| ๐ High Performance | Optimized algorithms for CPU and GPU |
| ๐งต Multi-threading | Parallel processing on CPU |
| ๐ฅ๏ธ GPU Acceleration | Support for NVIDIA (CUDA), AMD (ROCm), Apple (Metal), and Intel (oneAPI) |
| ๐ Python Integration | Full Python support via distance_transforms |
| ๐ Versatile Dimensions | Works with 1D, 2D, and 3D arrays |
| ๐ Well Documented | Comprehensive guides and examples |
Acknowledgements
This project would not be possible without several excellent Julia packages:
- KernelAbstractions.jl: Provides hardware-agnostic GPU code that runs across different GPU platforms
- AcceleratedKernels.jl: Makes it dead simple to write GPU kernels with normal Julia code
- PythonCall.jl: Powers the Python interoperability layer for seamless integration
- DLPack.jl: Enables zero-copy tensor sharing with PyTorch for efficient GPU operations
Why This Library?
| Distance Transforms | ImageMorphology.jl | SciPy | |
|---|---|---|---|
| Fast Distance Transform | โ โ | โ | โ |
| CPU Single-Threaded Support | โ | โ | โ |
| CPU Multi-Threaded Support | โ | โ | โ |
| NVIDIA/CUDA Support | โ | โ | โ |
| AMD/ROCM Support | โ | โ | โ |
| Apple/Metal Support | โ | โ | โ |
| Intel/oneAPI Support | โ | โ | โ |
| Python Integration | โ | โ | โ |
Choose Your Language
Julia
using DistanceTransforms
arr = rand([0, 1], 10, 10)
result = transform(boolean_indicator(arr))Python
import numpy as np
import distance_transforms as dts
arr = np.random.choice([0, 1], size=(10, 10)).astype(np.float32)
result = dts.transform(arr)Installation
Julia
using Pkg
Pkg.add("DistanceTransforms")Python
pip install distance_transformsCitation
If you use DistanceTransforms in your research, please cite:
@software{DistanceTransforms,
author = {Black, Dale and Contributors},
title = {DistanceTransforms: Fast Distance Transforms for Julia and Python},
url = {https://github.com/Dale-Black/DistanceTransforms.jl},
year = {2023}
}License
DistanceTransforms is available under the MIT License.