autods_pet.ops.stats#

Statistics helpers for voxel-level image analysis.

For computing multiple statistics on the same image/mask pair, prefer compute_stats() over calling individual functions (e.g. mean_in_mask(), max_in_mask()). compute_stats extracts the masked voxel array once and reuses it for all requested statistics, avoiding redundant O(n) array copies per call.

autods_pet.ops.stats.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.stats.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.stats.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.stats.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.stats.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

autods_pet.ops.stats.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.stats.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.stats.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.stats.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]