autods_pet.ops#

Operations subpackage: mask manipulation and statistics.

autods_pet.ops.compute_stats(stat_names, img, mask)[source]#

Compute multiple named statistics for img inside mask.

Parameters:
  • stat_names (list[str]) – Names like "mean", "median", "min", "max", "p90", "p95".

  • img (Image) – Scalar image (e.g. PET SUVbw).

  • mask (Image) – Binary mask selecting voxels of interest.

Returns:

{stat_name: value} for each requested stat.

Return type:

dict[str, float | None]

autods_pet.ops.count_voxels(mask)[source]#

Count non-zero voxels in a binary mask.

Parameters:

mask (Image) – Binary mask image.

Returns:

Number of non-zero voxels.

Return type:

int

autods_pet.ops.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.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.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.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.mask_volume_mm3(mask)[source]#

Compute the physical volume of non-zero voxels in mm3.

Parameters:

mask (Image) – Binary mask image with valid spacing metadata.

Returns:

Volume in mm3.

Return type:

float

autods_pet.ops.max_in_mask(img, mask)[source]#

Return the maximum voxel value inside mask.

Parameters:
  • img (Image) – Scalar image.

  • mask (Image) – Binary mask selecting the voxels of interest.

Returns:

The maximum value, or None if the mask is empty.

Return type:

float | None

autods_pet.ops.mean_in_mask(img, mask)[source]#

Return the arithmetic mean of voxel values inside mask.

Parameters:
  • img (Image) – Scalar image.

  • mask (Image) – Binary mask selecting the voxels of interest.

Returns:

The mean value, or None if the mask is empty.

Return type:

float | None

autods_pet.ops.min_in_mask(img, mask)[source]#

Return the minimum voxel value inside mask.

Parameters:
  • img (Image) – Scalar image.

  • mask (Image) – Binary mask selecting the voxels of interest.

Returns:

The minimum value, or None if the mask is empty.

Return type:

float | None

autods_pet.ops.percentile_in_mask(img, mask, pct)[source]#

Return the pct-th percentile of voxel values inside mask.

Parameters:
  • img (Image) – Scalar image (e.g. PET SUVbw).

  • mask (Image) – Binary mask selecting the voxels of interest.

  • pct (float) – Percentile in the range [0, 100].

Returns:

The requested percentile, or None if the mask is empty.

Return type:

float | None

Raises:

ValueError – If pct is outside [0, 100].

autods_pet.ops.shrinkage_report(original, refined)[source]#

Compute voxel-count and physical-volume deltas between two masks.

Parameters:
  • original (Image) – Binary mask before refinement (e.g. raw segmentation).

  • refined (Image) – Binary mask after refinement (e.g. eroded version).

Returns:

Keys: original_voxels, refined_voxels, original_volume_mm3, refined_volume_mm3, delta_voxels, delta_volume_mm3, shrinkage_pct.

Return type:

dict[str, Any]

autods_pet.ops.voxelwise_median(img, mask)[source]#

Return the median of voxel values inside mask.

Parameters:
  • img (Image) – Scalar image.

  • mask (Image) – Binary mask selecting the voxels of interest.

Returns:

The median value, or None if the mask is empty.

Return type:

float | None