Skip to content

morphology

voxel.morphology.dilate(volume, iterations=1, connectivity=1, iso_thresh=None) -> vx.Volume

Apply a binary dilation to the nonzero voxels of a volume.

Parameters:

  • iterations (int, default: 1 ) –

    Number of dilation iterations.

  • connectivity (int, default: 1 ) –

    Neighborhood connectivity: 1 includes face neighbors (6), 2 adds edge neighbors (18), and 3 adds corner neighbors (26).

  • iso_thresh (float, default: None ) –

    Spacing ratio (slice over in-plane spacing) at or above which the operation is applied only in-plane, i.e. the kernel is collapsed along the slice direction. If None, the operation is always treated as isotropic. Disabled by default.

Returns:

  • Volume

    Dilated binary volume of the input data type.

voxel.morphology.erode(volume, iterations=1, connectivity=1, iso_thresh=None) -> vx.Volume

Apply a binary erosion to the nonzero voxels of a volume. Voxels beyond the grid border are considered background.

Parameters:

  • iterations (int, default: 1 ) –

    Number of erosion iterations.

  • connectivity (int, default: 1 ) –

    Neighborhood connectivity: 1 includes face neighbors (6), 2 adds edge neighbors (18), and 3 adds corner neighbors (26).

  • iso_thresh (float, default: None ) –

    Spacing ratio (slice over in-plane spacing) at or above which the operation is applied only in-plane, i.e. the kernel is collapsed along the slice direction. If None, the operation is treated as isotropic. Disabled by default.

Returns:

  • Volume

    Eroded binary volume of the input data type.

voxel.morphology.close(volume, iterations=1, connectivity=1, iso_thresh=None) -> vx.Volume

Apply a binary closing (dilation followed by erosion) to the nonzero voxels of a volume, sealing gaps smaller than the effective kernel.

Parameters:

  • iterations (int, default: 1 ) –

    Number of dilation and erosion iterations.

  • connectivity (int, default: 1 ) –

    Neighborhood connectivity: 1 includes face neighbors (6), 2 adds edge neighbors (18), and 3 adds corner neighbors (26).

  • iso_thresh (float, default: None ) –

    Spacing ratio (slice over in-plane spacing) at or above which the operation is applied only in-plane, i.e. the kernel is collapsed along the slice direction. If None, the operation is treated as isotropic. Disabled by default.

Returns:

  • Volume

    Closed binary volume of the input data type.

voxel.morphology.open(volume, iterations=1, connectivity=1, iso_thresh=None) -> vx.Volume

Apply a binary opening (erosion followed by dilation) to the nonzero voxels of a volume, removing structures smaller than the effective kernel.

Parameters:

  • iterations (int, default: 1 ) –

    Number of erosion and dilation iterations.

  • connectivity (int, default: 1 ) –

    Neighborhood connectivity: 1 includes face neighbors (6), 2 adds edge neighbors (18), and 3 adds corner neighbors (26).

  • iso_thresh (float, default: None ) –

    Spacing ratio (slice over in-plane spacing) at or above which the operation is applied only in-plane, i.e. the kernel is collapsed along the slice direction. If None, the operation is treated as isotropic. Disabled by default.

Returns:

  • Volume

    Opened binary volume of the input data type.

voxel.morphology.connected_components(volume, connectivity=1, largest=False) -> vx.Volume

Label the connected components of the nonzero voxels in a volume.

Components are labeled in order of descending size, so the largest component always has label 1. Channels are labeled independently. Labeling runs on the CPU and the result is moved back to the device.

Parameters:

  • connectivity (int, default: 1 ) –

    Neighborhood connectivity: 1 includes face neighbors (6), 2 adds edge neighbors (18), and 3 adds corner neighbors (26).

  • largest (bool, default: False ) –

    If True, only the largest component is kept, producing a binary volume with label 1.

Returns:

  • Volume

    Integer label map volume.

voxel.morphology.flood_fill(volume, point, space='voxel', connectivity=1) -> vx.Volume

Flood fill a volume from a seed point, extracting the connected region of voxels that share the seed's value. Both foreground and background regions can be filled. Filling runs on the CPU and the result is moved back to the device.

Parameters:

  • point (Tensor) –

    A 3D seed coordinate.

  • space (Space, default: 'voxel' ) –

    The coordinate space of the seed point.

  • connectivity (int, default: 1 ) –

    Neighborhood connectivity: 1 includes face neighbors (6), 2 adds edge neighbors (18), and 3 adds corner neighbors (26).

Returns:

  • Volume

    Binary volume of the input data type marking the filled region.

voxel.morphology.fill_holes(volume, connectivity=1) -> vx.Volume

Fill enclosed background cavities (holes) in the nonzero regions of a volume. Background connected to the grid border is not considered a hole. Channels are filled independently. Filling runs on the CPU and the result is moved back to the device.

Parameters:

  • connectivity (int, default: 1 ) –

    Neighborhood connectivity: 1 includes face neighbors (6), 2 adds edge neighbors (18), and 3 adds corner neighbors (26).

Returns:

  • Volume

    Binary volume of the input data type with holes filled.