Skip to main content

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

Example

See our demo notebook

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

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

Metadata

Release files for torch-distmap 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torch-distmap 0.3.0
File Size Uploaded Provenance Actions
torch_distmap-0.3.0.tar.gz 25.9 kB Without provenance Details for torch_distmap-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torch-distmap 0.3.0
File Interpreter ABI Platform Actions
torch_distmap-0.3.0-py3-none-any.whl Python 3 none any Details for torch_distmap-0.3.0-py3-none-any.whl

Total release size: 37.5 kB

Release files / torch_distmap-0.3.0.tar.gz

Download URL torch_distmap-0.3.0.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
38f02f9891aae7c2262aba4f85be88ea3acc3c3eddb66c50423ea09a865b6de2
BLAKE2b-256 checksum
How to use checksums
9cfcf36cddcb73abc4b2edfa3010921b84c009b4bce2126684abc88c1325c541
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / torch_distmap-0.3.0-py3-none-any.whl

Download URL torch_distmap-0.3.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f55dc660901664b46bbd1f519f2b04af560ea674588aa38ae151aabafa2a11ff
BLAKE2b-256 checksum
How to use checksums
6c3c11fad2497d424cc27ab7591a35cd7311b77beee59ee618f4f4804a4434bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for torch-distmap 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page