Distance Transforms
torchmorph.euclidean_distance_transform
euclidean_distance_transform(
input,
sampling=None,
return_distances=True,
return_indices=False,
distances=None,
indices=None,
)
Compute the exact Euclidean distance to the nearest background point
Distances are computed independently for each batch and channel. Nonzero input values are foreground and zero values are background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Tensor
|
CUDA tensor with shape |
required |
sampling
|
float or sequence[float]
|
Positive spacing along each spatial axis. A scalar or one-element sequence is broadcast. |
None
|
return_distances
|
bool
|
Return a newly allocated distance tensor unless
|
True
|
return_indices
|
bool
|
Return a newly allocated nearest-background index
tensor unless |
False
|
distances
|
Tensor
|
Preallocated distance output with
the same shape and device as |
None
|
indices
|
Tensor
|
Preallocated index output with shape
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, Tensor] | None
|
torch.Tensor, tuple[torch.Tensor, torch.Tensor], or None: Requested |
Tensor | tuple[Tensor, Tensor] | None
|
newly allocated outputs. Distances have |
Tensor | tuple[Tensor, Tensor] | None
|
shape; indices have |
Tensor | tuple[Tensor, Tensor] | None
|
|
Tensor | tuple[Tensor, Tensor] | None
|
omitted from the return value, so the function returns |
Tensor | tuple[Tensor, Tensor] | None
|
every requested output is preallocated. |
torchmorph.chamfer_distance_transform
chamfer_distance_transform(
input,
metric="chessboard",
return_distances=True,
return_indices=False,
distances=None,
indices=None,
)
Compute a chamfer distance to the nearest background point
Distances are computed independently for each batch and channel. Nonzero input values are foreground and zero values are background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Tensor
|
CUDA tensor with shape |
required |
metric
|
str
|
|
'chessboard'
|
return_distances
|
bool
|
Return a newly allocated distance tensor unless
|
True
|
return_indices
|
bool
|
Return a newly allocated nearest-background index
tensor unless |
False
|
distances
|
Tensor
|
Preallocated distance output with
the same shape and device as |
None
|
indices
|
Tensor
|
Preallocated index output with shape
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, Tensor] | None
|
torch.Tensor, tuple[torch.Tensor, torch.Tensor], or None: Requested |
Tensor | tuple[Tensor, Tensor] | None
|
newly allocated outputs. Distances are |
Tensor | tuple[Tensor, Tensor] | None
|
|
Tensor | tuple[Tensor, Tensor] | None
|
value. |
torchmorph.brute_force_distance_transform
brute_force_distance_transform(
input,
metric="euclidean",
sampling=None,
return_distances=True,
return_indices=False,
distances=None,
indices=None,
)
Compute distances to background points by exhaustive search
This reference-style transform supports Euclidean, taxicab, and chessboard metrics and computes each batch and channel independently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
Tensor
|
CUDA tensor with shape |
required |
metric
|
str
|
One of |
'euclidean'
|
sampling
|
float or sequence[float]
|
Positive spatial spacing. A scalar or one-element sequence is broadcast to every axis. |
None
|
return_distances
|
bool
|
Return a newly allocated distance tensor unless
|
True
|
return_indices
|
bool
|
Return a newly allocated nearest-background index
tensor unless |
False
|
distances
|
Tensor
|
Preallocated distance output with
the same shape and device as |
None
|
indices
|
Tensor
|
Preallocated index output with shape
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, Tensor] | None
|
torch.Tensor, tuple[torch.Tensor, torch.Tensor], or None: Requested |
Tensor | tuple[Tensor, Tensor] | None
|
newly allocated outputs. Distances are |
Tensor | tuple[Tensor, Tensor] | None
|
|
Tensor | tuple[Tensor, Tensor] | None
|
value. |