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.

Example of a distance transform applied to various shapes

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))

Get started with Julia โ†’

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)

Get started with Python โ†’

Installation

Julia

using Pkg
Pkg.add("DistanceTransforms")

Python

pip install distance_transforms

Citation

If you use DistanceTransforms in your research, please cite:

@ARTICLE{10912438,
  author={Black, Dale and Li, Wenbo and Zhang, Qiyu and Molloi, Sabee},
  journal={IEEE Access}, 
  title={Accelerating Euclidean Distance Transforms: A Fast and Flexible Approach with Multi-Vendor GPU, Multi-Threading, and Multi-Language Support}, 
  year={2025},
  volume={},
  number={},
  pages={1-1},
  keywords={Transforms;Graphics processing units;Benchmark testing;Euclidean distance;Three-dimensional displays;Image segmentation;Hardware;Python;Metals;Arrays;Distance Transform;Hardware Acceleration;Hausdorff Distance;High Performance Computing;Image Processing;Medical Image Analysis;Parallel Computing;Segmentation;Skeletonization},
  doi={10.1109/ACCESS.2025.3548563}}

License

DistanceTransforms is available under the MIT License.