Skip to content

MolloiLab/distance_transforms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

distance_transforms

Documentation

Python bindings for the Julia DistanceTransforms.jl package, providing efficient Euclidean distance transforms for arrays.

Installation

pip install distance_transforms

Requirements

  • Python 3.11+
  • Julia 1.10+ or 1.11
  • Required Julia packages will be automatically installed on first use

Usage

Basic Example

import numpy as np
import distance_transforms as dts

# Create a binary array (1's for foreground, 0's for background)
arr = np.zeros((5, 5), dtype=np.uint8)
arr[2, 2] = 1  # Set center point as foreground

# Compute distance transform
# Returns squared distances from each point to the nearest foreground point
distances = dts.transform(arr)
print(distances)

CUDA Example (Optional)

If you have CUDA available and PyTorch installed:

import torch
import distance_transforms as dts

# Create a binary tensor on GPU
tensor = torch.zeros((5, 5), dtype=torch.bool, device="cuda")
tensor[2, 2] = True

# Compute distance transform on GPU
distances = dts.transform_cuda(tensor)
print(distances)

About

This package is a Python wrapper around DistanceTransforms.jl, which provides efficient implementations of Euclidean distance transforms. The distance transform computes, for each pixel in an image, the squared Euclidean distance to the nearest non-zero pixel.

On first use, the package will set up the required Julia environment automatically.

Features

  • Fast CPU implementation using the Felzenszwalb algorithm
  • Optional GPU acceleration with CUDA support
  • Simple, NumPy-compatible API
  • Support for multidimensional arrays

Documentation

For comprehensive documentation on the algorithms and detailed usage, please refer to the DistanceTransforms.jl documentation.

License

MIT

About

Python bindings for the Julia DistanceTransforms.jl package, providing efficient Euclidean distance transforms for arrays.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages