Euclidean distance transform in PyTorch
Project description
torch-distmap
Euclidean distance transform in PyTorch.
This is an implementation of the algorithm from the paper
"Distance Transforms of Sampled Functions"
Pedro F. Felzenszwalb & Daniel P. Huttenlocher
Theory of Computing (2012)
Although it is in PyTorch, our implementation performs loops across voxels and hence quite slow. Moreover, it takes masks as an input and therefore does not allow backpropagation.
Installation
Dependency
torch >= 1.3
Conda
conda install torch-distmap -c balbasty -c pytorch
Pip
pip install torch-distmap
API
euclidean_distance_transform(x, ndim=None, vx=1)
"""Compute the Euclidean distance transform of a binary image
Parameters
----------
x : (..., *spatial) tensor
Input tensor. Zeros will stay zero, and the distance will
be propagated into nonzero voxels.
ndim : int, default=`x.dim()`
Number of spatial dimensions
vx : [sequence of] float, default=1
Voxel size
Returns
-------
d : (..., *spatial) tensor
Distance map
"""
euclidean_signed_transform(x, ndim=None, vx=1)
"""Compute the signed Euclidean distance transform of a binary image
Parameters
----------
x : (..., *spatial) tensor
Input tensor.
A negative distance will propagate into zero voxels and
a positive distance will propagate into nonzero voxels.
ndim : int, default=`x.dim()`
Number of spatial dimensions
vx : [sequence of] float, default=1
Voxel size
Returns
-------
d : (..., *spatial) tensor
Signed distance map
"""
l1_distance_transform(x, ndim=None, vx=1)
"""Compute the L1 distance transform of a binary image
Parameters
----------
x : (..., *spatial) tensor
Input tensor. Zeros will stay zero, and the distance will
be propagated into nonzero voxels.
ndim : int, default=`x.dim()`
Number of spatial dimensions
vx : [sequence of] float, default=1
Voxel size
Returns
-------
d : (..., *spatial) tensor
Distance map
"""
l1_signed_transform(x, ndim=None, vx=1)
"""Compute the signed L1 distance transform of a binary image
Parameters
----------
x : (..., *spatial) tensor
Input tensor.
A negative distance will propagate into zero voxels and
a positive distance will propagate into nonzero voxels.
ndim : int, default=`x.dim()`
Number of spatial dimensions
vx : [sequence of] float, default=1
Voxel size
Returns
-------
d : (..., *spatial) tensor
Signed distance map
"""
Related packages
-
edt : a very fast CPU implementation of the same algorithm, written in C.
-
scipy.ndimage.distance_transform_edt : reference implementation, written in C, based on the paper
"A linear time algorithm for computing exact euclidean distance transforms of binary images in arbitrary dimensions"
C. R. Maurer, Jr., R. Qi, V. Raghavan
IEEE Trans. PAMI 25, 265-270, (2003)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file torch-distmap-0.2.0.tar.gz
.
File metadata
- Download URL: torch-distmap-0.2.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 634ed0d63c2f096fa9b2ac6a57d1e2cc4528eef11ee75488265d8cce9a27b574 |
|
MD5 | 580ac376853ac302f66542a37b13979b |
|
BLAKE2b-256 | 87dad20f54f2d1a2f7890e12214cb68cd98bb4de0ec1af18827b9179940179d2 |
File details
Details for the file torch_distmap-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: torch_distmap-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 094c78e85bb0ed1c91c81a69dc2756d8c63fcbea0dd3540aa779390582a947b8 |
|
MD5 | 92729f5c8c71ae4ec1d18f97cd5d210f |
|
BLAKE2b-256 | 42f59d0f7e1ea7fb62af5fd6445cd1600521ae9ab69b8697f4263957f8458af2 |