@@ -20,15 +20,15 @@ class UnsupportedModalityError(ValueError):
2020def get_ct_preprocessing_pipeline () -> Compose :
2121 """
2222 Create a preprocessing pipeline for CT (Computed Tomography) images.
23-
23+
2424 Returns:
2525 Compose: A transform composition for CT preprocessing.
26-
26+
2727 The pipeline consists of:
2828 1. LoadImage - Load DICOM series
2929 2. EnsureChannelFirst - Add channel dimension
3030 3. ScaleIntensityRange - Scale Hounsfield Units (HU) from [-1000, 400] to [0, 1]
31-
31+
3232 Note:
3333 The HU window [-1000, 400] is a common soft tissue window.
3434 """
@@ -42,15 +42,15 @@ def get_ct_preprocessing_pipeline() -> Compose:
4242def get_mri_preprocessing_pipeline () -> Compose :
4343 """
4444 Create a preprocessing pipeline for MRI (Magnetic Resonance Imaging) images.
45-
45+
4646 Returns:
4747 Compose: A transform composition for MRI preprocessing.
48-
48+
4949 The pipeline consists of:
5050 1. LoadImage - Load DICOM series
5151 2. EnsureChannelFirst - Add channel dimension
5252 3. NormalizeIntensity - Normalize non-zero voxels
53-
53+
5454 Note:
5555 Normalization is applied only to non-zero voxels to avoid bias from background.
5656 """
@@ -64,30 +64,30 @@ def get_mri_preprocessing_pipeline() -> Compose:
6464def preprocess_dicom_series (path : str , modality : str ):
6565 """
6666 Preprocess a DICOM series based on the imaging modality.
67-
67+
6868 Args:
6969 path: Path to the DICOM series directory or file.
7070 modality: Imaging modality (case-insensitive). Supported values:
7171 "CT", "MR", "MRI" (MRI is treated as synonym for MR).
72-
72+
7373 Returns:
7474 The preprocessed image data.
75-
75+
7676 Raises:
7777 ModalityTypeError: If modality is not a string.
7878 UnsupportedModalityError: If modality is not supported.
7979 """
8080 # Validate input type
8181 if not isinstance (modality , str ):
8282 raise ModalityTypeError (f"modality must be a string, got { type (modality ).__name__ } " )
83-
83+
8484 # Normalize modality string (strip whitespace, convert to uppercase)
8585 modality_clean = modality .strip ().upper ()
86-
86+
8787 # Map MRI to MR (treat as synonyms)
8888 if modality_clean == "MRI" :
8989 modality_clean = "MR"
90-
90+
9191 # Select appropriate preprocessing pipeline
9292 if modality_clean == "CT" :
9393 pipeline = get_ct_preprocessing_pipeline ()
@@ -98,16 +98,16 @@ def preprocess_dicom_series(path: str, modality: str):
9898 raise UnsupportedModalityError (
9999 f"Unsupported modality '{ modality } '. Supported modalities: { ', ' .join (supported )} "
100100 )
101-
101+
102102 # Apply preprocessing pipeline
103103 return pipeline (path )
104104
105105
106106# Export the public API
107107__all__ = [
108108 "ModalityTypeError" ,
109- "UnsupportedModalityError" ,
109+ "UnsupportedModalityError" ,
110110 "get_ct_preprocessing_pipeline" ,
111111 "get_mri_preprocessing_pipeline" ,
112112 "preprocess_dicom_series" ,
113- ]
113+ ]
0 commit comments