autods_pet.ops.masks#

Mask operations for multilabel segmentations.

autods_pet.ops.masks.label_mask(seg, label)[source]#

Extract a binary mask for a single label from a multilabel segmentation.

Parameters:
  • seg (Image) – Multilabel segmentation image (integer-valued).

  • label (int) – The label value to extract.

Returns:

Binary uint8 mask where the selected label is 1 and all else is 0.

Return type:

Image

autods_pet.ops.masks.label_union(seg, labels)[source]#

Binary mask that is the union of several labels.

Parameters:
  • seg (Image) – Multilabel segmentation image (integer-valued).

  • labels (list[int]) – Label values to include. An empty list returns an all-zero mask.

Returns:

Binary uint8 mask where any of the selected labels is 1.

Return type:

Image

autods_pet.ops.masks.keep_largest_component(mask)[source]#

Keep only the largest connected component of a binary mask.

Parameters:

mask (Image) – Binary mask (non-zero values are foreground).

Returns:

Binary uint8 mask containing only the largest connected component. If the mask is empty, returns the input unchanged.

Return type:

Image

autods_pet.ops.masks.fill_holes(mask, max_hole_volume_mm3=None)[source]#

Fill holes in a binary mask.

Parameters:
  • mask (Image) – Binary mask.

  • max_hole_volume_mm3 (float | None (default: None)) – If None, fills all holes (original behavior). If set, only fills holes whose volume is below this threshold (mm³). Large holes (e.g. portal vein in liver) are preserved.

Returns:

Binary uint8 mask with holes filled.

Return type:

Image

autods_pet.ops.masks.subtract_mask(base, subtract)[source]#

Set difference of two binary masks (base minus subtract).

Parameters:
  • base (Image) – Binary mask to subtract from.

  • subtract (Image) – Binary mask whose foreground voxels are removed from base.

Returns:

Binary uint8 mask containing voxels in base that are not in subtract.

Return type:

Image