Skip to main content

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

pip install git+https://github.com/balbasty/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

"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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch-distmap-0.1.0.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

torch_distmap-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file torch-distmap-0.1.0.tar.gz.

File metadata

  • Download URL: torch-distmap-0.1.0.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for torch-distmap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dbc57eaa42d037bc31ff2d8702928bcc05de44cfaf7b57b2ba784551e91a244a
MD5 be2a515f13d368abca80532f63864606
BLAKE2b-256 15a96b38ee7fb8604c978aed27dd8152f8e35d518629855bd6ca4b8e127ec1dc

See more details on using hashes here.

File details

Details for the file torch_distmap-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for torch_distmap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b45f6db27507e38c3b12839f0c1e0b0a1322972d85993d81ff997d01c2bb16bb
MD5 7cebc8c3ef46082b1052272ad58c5b44
BLAKE2b-256 4f1714d4c8db0594f4024978ee7f61d0ff5c85ce63d23673b23340242ddf8589

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page