1515This module provides modality-specific preprocessing pipelines for common medical imaging modalities.
1616"""
1717
18- from monai .data import MetaTensor
18+ from typing import Any
19+
1920from monai .transforms import (
2021 Compose ,
2122 EnsureChannelFirst ,
@@ -38,9 +39,9 @@ def get_ct_preprocessing_pipeline() -> Compose:
3839 Create a preprocessing pipeline for CT images.
3940
4041 Returns:
41- Compose: Transform composition for CT preprocessing. Applies HU windowing
42- [-1000, 400] scaled to [0, 1] with clipping, suitable for soft tissue
43- and lung visualization .
42+ Compose: Transform composition for CT preprocessing.
43+ Applies Hounsfield Unit (HU) windowing [-1000, 400] scaled to [0, 1].
44+ This range captures lung (-1000 to -400 HU) and soft tissue (0 to 100 HU) contrast .
4445 """
4546 return Compose (
4647 [
@@ -62,9 +63,9 @@ def get_mri_preprocessing_pipeline() -> Compose:
6263 Create a preprocessing pipeline for MRI images.
6364
6465 Returns:
65- Compose: Transform composition for MRI preprocessing. Normalizes using
66- mean/std computed over non-zero voxels only, appropriate for MRI
67- data with background regions .
66+ Compose: Transform composition for MRI preprocessing.
67+ Normalizes intensities using nonzero voxels only, excluding background regions
68+ typical in MRI acquisitions .
6869 """
6970 return Compose (
7071 [
@@ -75,22 +76,23 @@ def get_mri_preprocessing_pipeline() -> Compose:
7576 )
7677
7778
78- def preprocess_dicom_series (path : str , modality : str ) -> MetaTensor :
79+ def preprocess_dicom_series (path : str , modality : str ) -> Any :
7980 """Preprocess a DICOM series or file based on imaging modality.
8081
8182 Args:
8283 path: Path to the DICOM file or directory containing a DICOM series.
8384 modality: Imaging modality. Supported values are "CT", "MR", and "MRI" (case-insensitive).
8485
8586 Returns:
86- MetaTensor : Preprocessed image tensor with metadata .
87+ Any : Preprocessed image data .
8788
8889 Raises:
8990 ModalityTypeError: If modality is not a string.
9091 UnsupportedModalityError: If the provided modality is not supported.
9192 """
9293 if not isinstance (modality , str ):
93- raise ModalityTypeError ("modality must be a string" )
94+ error_msg = "modality must be a string"
95+ raise ModalityTypeError (error_msg )
9496
9597 modality_clean = modality .strip ().upper ()
9698
@@ -99,9 +101,11 @@ def preprocess_dicom_series(path: str, modality: str) -> MetaTensor:
99101 elif modality_clean == "CT" :
100102 pipeline = get_ct_preprocessing_pipeline ()
101103 else :
102- raise UnsupportedModalityError (
103- f"Unsupported modality '{ modality } '. Supported modalities: CT, MR, MRI"
104+ error_msg = (
105+ f"Unsupported modality '{ modality } '. "
106+ f"Supported modalities: CT, MR, MRI"
104107 )
108+ raise UnsupportedModalityError (error_msg )
105109
106110 return pipeline (path )
107111
0 commit comments