Skip to content

Commit 5a4fbb5

Browse files
Final fixes per CodeRabbit review
- Improve CT docstring with clinical rationale for HU windowing [-1000, 400] - Improve MRI docstring explaining nonzero=True for background exclusion - Add explicit test_mr_modality_distinct() for MR modality testing - Update integration test to cover CT, MR, and MRI modalities - Update return type annotation and docstring for MetaTensor Signed-off-by: Hitendrasinh Rathod <[email protected]>
1 parent b3e8f87 commit 5a4fbb5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

monai/tests/test_clinical_preprocessing.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def test_modality_case_insensitivity(mock_load):
9090
assert result is not None
9191

9292

93+
@patch("monai.transforms.clinical_preprocessing.LoadImage")
94+
def test_mr_modality_distinct(mock_load):
95+
"""Test MR modality is handled separately from MRI."""
96+
mock_load.return_value = Mock(return_value=Mock())
97+
result = preprocess_dicom_series("dummy.dcm", "MR")
98+
assert result is not None
99+
100+
93101
def test_preprocess_dicom_series_integration(tmp_path):
94102
"""Integration test with dummy NIfTI file."""
95103
# Create a dummy NIfTI file for testing
@@ -98,8 +106,8 @@ def test_preprocess_dicom_series_integration(tmp_path):
98106

99107
write_nifti(dummy_data, test_file)
100108

101-
# Test with each modality
102-
for modality in ["CT", "MRI"]:
109+
# Test with each modality (including both MR and MRI)
110+
for modality in ["CT", "MR", "MRI"]:
103111
result = preprocess_dicom_series(str(test_file), modality)
104112
assert result is not None
105113
assert hasattr(result, "shape")

monai/transforms/clinical_preprocessing.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
This module provides modality-specific preprocessing pipelines for common medical imaging modalities.
1616
"""
1717

18-
from typing import Any
19-
18+
from monai.data import MetaTensor
2019
from monai.transforms import (
2120
Compose,
2221
EnsureChannelFirst,
@@ -39,7 +38,9 @@ def get_ct_preprocessing_pipeline() -> Compose:
3938
Create a preprocessing pipeline for CT images.
4039
4140
Returns:
42-
Compose: Transform composition for CT preprocessing.
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.
4344
"""
4445
return Compose(
4546
[
@@ -61,7 +62,9 @@ def get_mri_preprocessing_pipeline() -> Compose:
6162
Create a preprocessing pipeline for MRI images.
6263
6364
Returns:
64-
Compose: Transform composition for MRI preprocessing.
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.
6568
"""
6669
return Compose(
6770
[
@@ -72,15 +75,15 @@ def get_mri_preprocessing_pipeline() -> Compose:
7275
)
7376

7477

75-
def preprocess_dicom_series(path: str, modality: str) -> Any:
78+
def preprocess_dicom_series(path: str, modality: str) -> MetaTensor:
7679
"""Preprocess a DICOM series or file based on imaging modality.
7780
7881
Args:
7982
path: Path to the DICOM file or directory containing a DICOM series.
8083
modality: Imaging modality. Supported values are "CT", "MR", and "MRI" (case-insensitive).
8184
8285
Returns:
83-
The preprocessed image data.
86+
MetaTensor: Preprocessed image tensor with metadata.
8487
8588
Raises:
8689
ModalityTypeError: If modality is not a string.

0 commit comments

Comments
 (0)