Skip to content

fiery.distmap

Euclidean distance transform in PyTorch.

Functions:

l1_distance_transform

l1_distance_transform(x: Tensor, ndim: int | None = None, vx: float | Sequence[float] = 1) -> Tensor

Compute the L1 distance transform of a binary image

Parameters:

Name Type Description Default
x (..., *spatial) tensor

Input tensor. Zeros will stay zero, and the distance will be propagated into nonzero voxels.

required
ndim int

Number of spatial dimensions

`x.dim()`
vx [sequence of] float

Voxel size

1

Returns:

Name Type Description
d (..., *spatial) tensor

Distance map

References

..[1] "Distance Transforms of Sampled Functions" Pedro F. Felzenszwalb & Daniel P. Huttenlocher Theory of Computing (2012) https://www.theoryofcomputing.org/articles/v008a019/v008a019.pdf

l1_signed_transform

l1_signed_transform(x: Tensor, ndim: int | None = None, vx: float | Sequence[float] = 1) -> Tensor

Compute the signed L1 distance transform of a binary image

Parameters:

Name Type Description Default
x (..., *spatial) tensor

Input tensor. A negative distance will propagate into zero voxels and a positive distance will propagate into nonzero voxels.

required
ndim int

Number of spatial dimensions

`x.dim()`
vx [sequence of] float

Voxel size

1

Returns:

Name Type Description
d (..., *spatial) tensor

Signed distance map

References

..[1] "Distance Transforms of Sampled Functions" Pedro F. Felzenszwalb & Daniel P. Huttenlocher Theory of Computing (2012) https://www.theoryofcomputing.org/articles/v008a019/v008a019.pdf

euclidean_distance_transform

euclidean_distance_transform(x: Tensor, ndim: int | None = None, vx: float | Sequence[float] = 1, squared: bool = False) -> Tensor

Compute the Euclidean distance transform of a binary image

Parameters:

Name Type Description Default
x (..., *spatial) tensor

Input tensor. Zeros will stay zero, and the distance will be propagated into nonzero voxels.

required
ndim int

Number of spatial dimensions

`x.dim()`
vx [sequence of] float

Voxel size

1
squared bool

Return the squared distance map, skipping the final square root.

False

Returns:

Name Type Description
d (..., *spatial) tensor

Distance map (or squared distance map, if squared=True)

References

..[1] "Distance Transforms of Sampled Functions" Pedro F. Felzenszwalb & Daniel P. Huttenlocher Theory of Computing (2012) https://www.theoryofcomputing.org/articles/v008a019/v008a019.pdf

euclidean_signed_transform

euclidean_signed_transform(x: Tensor, ndim: int | None = None, vx: float | Sequence[float] = 1, squared: bool = False) -> Tensor

Compute the signed Euclidean distance transform of a binary image

Parameters:

Name Type Description Default
x (..., *spatial) tensor

Input tensor. A negative distance will propagate into zero voxels and a positive distance will propagate into nonzero voxels.

required
ndim int

Number of spatial dimensions

`x.dim()`
vx [sequence of] float

Voxel size

1
squared bool

Return the squared distance map, skipping the final square root.

False

Returns:

Name Type Description
d (..., *spatial) tensor

Signed distance map (or squared signed distance map, if squared=True)

References

..[1] "Distance Transforms of Sampled Functions" Pedro F. Felzenszwalb & Daniel P. Huttenlocher Theory of Computing (2012) https://www.theoryofcomputing.org/articles/v008a019/v008a019.pdf