autods_pet.imaging.geometry#

Geometry checks and spatial alignment for SimpleITK images.

autods_pet.imaging.geometry.check_same_geometry(a, b, tol=0.0001)[source]#

Check whether two images share the same spatial geometry.

Compares size, spacing, origin, and direction cosine matrix.

Parameters:
  • a (Image) – First image.

  • b (Image) – Second image.

  • tol (float (default: 0.0001)) – Absolute tolerance for floating-point comparisons of spacing, origin, and direction elements.

Returns:

True if the images match in size, spacing, origin, and direction within tol.

Return type:

bool

autods_pet.imaging.geometry.check_sub_geometry(a, b, tol=0.0001)[source]#

Check whether a lives on a compatible voxel grid as b (sub-volume).

Returns True when spacing matches within tol and direction cosine axes are parallel (signs may differ - a Z-flip between LPS and RAS conventions is allowed). Size and origin may differ freely.

This identifies the common DICOM SEG case where the mask only covers the slices that contain a contour (fewer slices, different origin) and may have been exported with a flipped axis convention.

Parameters:
  • a (Image) – Candidate sub-volume (e.g. a partial-FOV mask).

  • b (Image) – Reference volume (e.g. full PET or CT).

  • tol (float (default: 0.0001)) – Absolute tolerance for floating-point comparisons.

Returns:

True if spacing matches and direction axes are parallel.

Return type:

bool

autods_pet.imaging.geometry.resample_to_reference(mask, reference)[source]#

Resample mask onto the reference grid (zero-padded, nearest-neighbour).

Used to embed a partial-FOV binary mask (e.g. a DICOM SEG covering only a few slices) into the full reference volume. Voxels outside the mask’s original extent are set to 0.

Parameters:
  • mask (Image) – Binary mask (sub-volume).

  • reference (Image) – Full-size reference image whose grid defines the output.

Returns:

Resampled mask with the same size, origin, spacing, and direction as reference.

Return type:

Image