Structuring Elements
Create and expand multidimensional connectivity structures for morphological operations.
torchmorph.generate_binary_structure
Generate an N-dimensional binary structuring element
The returned tensor has shape (3,) * rank. Elements whose offset differs
from the center along at most connectivity axes are True; all other
elements are False. This matches SciPy's
ndimage.generate_binary_structure connectivity convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rank
|
int
|
Number of spatial dimensions in the structuring element.
Must be at least |
required |
connectivity
|
int
|
Neighborhood connectivity from |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Boolean tensor with shape |
torchmorph.iterate_structure
Dilate a binary structuring element with itself repeatedly
The result is equivalent to applying the original structuring element
iterations times in a morphology operation. Nonzero input values are
treated as part of the structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Tensor
|
N-dimensional binary structuring element. |
required |
iterations
|
int
|
Number of copies to combine. Values below |
required |
origin
|
int or tuple[int, ...]
|
Original anchor offset. A scalar is applied to every dimension. When supplied, the adjusted origin is returned with the iterated structure. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, list[int]]
|
torch.Tensor or tuple[torch.Tensor, list[int]]: Boolean iterated |
Tensor | tuple[Tensor, list[int]]
|
structure. If |
Tensor | tuple[Tensor, list[int]]
|
with each origin component multiplied by |