Skip to main content

transforms

MONAI transform utilities for Bitfount integration.

This module provides transforms for converting Bitfount datasource output to MONAI MetaTensor format, enabling seamless integration between Bitfount's data pipeline and MONAI's preprocessing transforms.

Also provides the Restored transform for spatial restoration of predictions back to the original image space after inference.

Classes

BitfountToMetaTensord

class BitfountToMetaTensord(    keys: KeysCollection,    meta_key_postfix: str = 'meta_dict',    affine_key: str = 'Affine',    original_affine_key: str = 'OriginalAffine',    pixdim_key: str = 'Pixdim',    spatial_shape_key: str = 'SpatialShape',    filepath_key: str = 'FilePath',    channel_dim_key: str = 'OriginalChannelDim',    allow_missing_keys: bool = False,):

Convert Bitfount NIFTISource output to MONAI MetaTensor format.

This transform converts numpy arrays and metadata from Bitfount's NIFTISource into MONAI MetaTensors with complete metadata for downstream MONAI transforms such as Orientationd, Spacingd, and SaveImaged.

Follows MONAI's LoadImaged pattern: for each key, creates a MetaTensor and optionally stores metadata in a separate {key}_meta_dict dictionary.

The transform expects the following metadata keys from

Arguments

  • keys: Keys of the data dictionary to convert to MetaTensor.
  • meta_key_postfix: Postfix for metadata dictionary key. If set, stores metadata in {key}_{meta_key_postfix}. Defaults to "meta_dict" to match MONAI's LoadImaged pattern.
  • affine_key: Key for the 4x4 affine matrix. Defaults to "Affine".
  • original_affine_key: Key for the original affine. Defaults to "OriginalAffine".
  • pixdim_key: Key for voxel spacing array. Defaults to "Pixdim".
  • spatial_shape_key: Key for spatial shape tuple. Defaults to "SpatialShape".
  • filepath_key: Key for full file path. Defaults to "FilePath".
  • channel_dim_key: Key for channel dimension. Defaults to "OriginalChannelDim".
  • allow_missing_keys: Don't raise error if keys are missing.

Ancestors

Restored

class Restored(    keys: KeysCollection,    ref_image: str,    has_channel: bool = True,    invert_orient: bool = True,    mode: Union[str, InterpolateMode] = nearest,    align_corners: Union[Sequence[Optional[bool]], Optional[bool]] = None,    meta_key_postfix: str = 'meta_dict',):

Restore predictions to original image space.

This transform restores prediction outputs (e.g., segmentation masks) back to the original image space by reversing spatial transformations applied during preprocessing. It handles:

  1. Spacing restoration: Resizes predictions back to original spatial shape if they were resampled during preprocessing (e.g., by Spacingd).
  2. Orientation restoration: Optionally inverts orientation changes to match the original image orientation (e.g., if Orientationd was applied).
  3. Affine restoration: Updates the prediction's metadata to use the original affine matrix for correct world-space alignment when saving.

This is modeled after MONAILabel's Restored transform but adapted for Bitfount's inference pipeline.

Arguments

  • keys: Keys of the prediction data to restore (e.g., ["pred"]).
  • ref_image: Key of the reference image containing original metadata.
  • has_channel: Whether predictions have a channel dimension. Defaults to True.
  • invert_orient: Whether to invert orientation changes. Defaults to True for full spatial restoration.
  • mode: Interpolation mode for resizing. Use "nearest" for segmentation masks to avoid interpolation artifacts. Defaults to InterpolateMode.NEAREST.
  • align_corners: Align corners parameter for interpolation. Defaults to None.
  • meta_key_postfix: Postfix for metadata dictionary key. Defaults to "meta_dict".

Note For segmentation outputs, always use mode="nearest" to prevent interpolation artifacts that could introduce invalid label values.

Ancestors