Skip to content

Commit aeabbbd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5394658 commit aeabbbd

File tree

2 files changed

+181
-181
lines changed

2 files changed

+181
-181
lines changed

monai/tests/test_clinical_preprocessing.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
" \"\"\"\n",
2424
" # Mock CT image with Hounsfield Units\n",
2525
" sample_ct = np.random.randint(-1024, 2048, size=(64, 64, 64), dtype=np.int16)\n",
26-
" \n",
26+
"\n",
2727
" transform = CTWindowingTransform()\n",
2828
" output = transform(sample_ct)\n",
29-
" \n",
29+
"\n",
3030
" # Output must be in [0,1]\n",
3131
" assert output.min() >= 0.0\n",
3232
" assert output.max() <= 1.0\n",
@@ -40,10 +40,10 @@
4040
" \"\"\"\n",
4141
" # Mock MRI image with random float values\n",
4242
" sample_mri = np.random.rand(64, 64, 64)\n",
43-
" \n",
43+
"\n",
4444
" transform = MRINormalizationTransform()\n",
4545
" output = transform(sample_mri)\n",
46-
" \n",
46+
"\n",
4747
" # Shape should be preserved\n",
4848
" assert output.shape == sample_mri.shape\n",
4949
" # Values should be roughly normalized (mean near 0, std near 1)\n",
Lines changed: 177 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,183 +1,183 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"id": "WK53GWYq4eo1",
6-
"metadata": {
7-
"id": "WK53GWYq4eo1"
8-
},
9-
"source": [
10-
"# Clinical DICOM CT and MRI Preprocessing with MONAI\n",
11-
"This notebook demonstrates inference-time preprocessing pipelines for CT and MRI DICOM series using MONAI, suitable for PACS/RIS workflows in hospital radiology environments.\n",
12-
"**Note:** This notebook focuses on preprocessing only and excludes training or patient-identifiable data."
13-
]
14-
},
15-
{
16-
"cell_type": "code",
17-
"execution_count": 1,
18-
"id": "LTKh48zD4eo4",
19-
"metadata": {
20-
"colab": {
21-
"base_uri": "https://localhost:8080/"
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "WK53GWYq4eo1",
6+
"metadata": {
7+
"id": "WK53GWYq4eo1"
8+
},
9+
"source": [
10+
"# Clinical DICOM CT and MRI Preprocessing with MONAI\n",
11+
"This notebook demonstrates inference-time preprocessing pipelines for CT and MRI DICOM series using MONAI, suitable for PACS/RIS workflows in hospital radiology environments.\n",
12+
"**Note:** This notebook focuses on preprocessing only and excludes training or patient-identifiable data."
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 1,
18+
"id": "LTKh48zD4eo4",
19+
"metadata": {
20+
"colab": {
21+
"base_uri": "https://localhost:8080/"
22+
},
23+
"id": "LTKh48zD4eo4",
24+
"outputId": "dcdc9430-1d52-4272-9079-8faba741099e"
25+
},
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"\u001b[?25l \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m0.0/2.7 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m\u001b[90m\u257a\u001b[0m\u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m1.9/2.7 MB\u001b[0m \u001b[31m53.8 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[91m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m\u001b[91m\u2578\u001b[0m \u001b[32m2.7/2.7 MB\u001b[0m \u001b[31m43.7 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m2.7/2.7 MB\u001b[0m \u001b[31m21.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
32+
"\u001b[?25h\u001b[?25l \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m0.0/2.4 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m\u001b[91m\u2578\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m147.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m38.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
33+
"\u001b[?25h"
34+
]
35+
}
36+
],
37+
"source": [
38+
"# Install required packages\n",
39+
"!pip install monai pydicom nibabel --quiet"
40+
]
41+
},
42+
{
43+
"cell_type": "markdown",
44+
"id": "gyAtaTBP4eo7",
45+
"metadata": {
46+
"id": "gyAtaTBP4eo7"
47+
},
48+
"source": [
49+
"## Import Libraries"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 5,
55+
"id": "k2DfCDZM4eo8",
56+
"metadata": {
57+
"id": "k2DfCDZM4eo8"
58+
},
59+
"outputs": [],
60+
"source": [
61+
"from monai.transforms import (\n",
62+
" LoadImage,\n",
63+
" EnsureChannelFirst,\n",
64+
" ScaleIntensityRange,\n",
65+
" NormalizeIntensity,\n",
66+
" Compose\n",
67+
")\n",
68+
"import numpy as np"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"id": "HAxGJVgy4eo8",
74+
"metadata": {
75+
"id": "HAxGJVgy4eo8"
76+
},
77+
"source": [
78+
"## Define Preprocessing Pipelines"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 6,
84+
"id": "cP-zDmqu4eo8",
85+
"metadata": {
86+
"id": "cP-zDmqu4eo8"
87+
},
88+
"outputs": [],
89+
"source": [
90+
"def get_ct_preprocessing_pipeline():\n",
91+
" return Compose([\n",
92+
" LoadImage(image_only=True),\n",
93+
" EnsureChannelFirst(),\n",
94+
" ScaleIntensityRange(a_min=-1000, a_max=400, b_min=0.0, b_max=1.0, clip=True)\n",
95+
" ])\n",
96+
"\n",
97+
"def get_mri_preprocessing_pipeline():\n",
98+
" return Compose([\n",
99+
" LoadImage(image_only=True),\n",
100+
" EnsureChannelFirst(),\n",
101+
" NormalizeIntensity(nonzero=True)\n",
102+
" ])"
103+
]
104+
},
105+
{
106+
"cell_type": "markdown",
107+
"id": "OuRHidt_4eo9",
108+
"metadata": {
109+
"id": "OuRHidt_4eo9"
110+
},
111+
"source": [
112+
"## Preprocessing Function"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": 7,
118+
"id": "BcGeKvkc4eo-",
119+
"metadata": {
120+
"id": "BcGeKvkc4eo-"
121+
},
122+
"outputs": [],
123+
"source": [
124+
"def preprocess_dicom_series(dicom_path, modality):\n",
125+
" modality = modality.upper()\n",
126+
" if modality == 'CT':\n",
127+
" transform = get_ct_preprocessing_pipeline()\n",
128+
" elif modality == 'MRI':\n",
129+
" transform = get_mri_preprocessing_pipeline()\n",
130+
" else:\n",
131+
" raise ValueError(\"Unsupported modality. Use 'CT' or 'MRI'.\")\n",
132+
" image = transform(dicom_path)\n",
133+
" return image"
134+
]
135+
},
136+
{
137+
"cell_type": "markdown",
138+
"id": "3bWBPrp44eo-",
139+
"metadata": {
140+
"id": "3bWBPrp44eo-"
141+
},
142+
"source": [
143+
"## Example Usage"
144+
]
22145
},
23-
"id": "LTKh48zD4eo4",
24-
"outputId": "dcdc9430-1d52-4272-9079-8faba741099e"
25-
},
26-
"outputs": [
27146
{
28-
"name": "stdout",
29-
"output_type": "stream",
30-
"text": [
31-
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/2.7 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━\u001b[0m \u001b[32m1.9/2.7 MB\u001b[0m \u001b[31m53.8 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m2.7/2.7 MB\u001b[0m \u001b[31m43.7 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.7/2.7 MB\u001b[0m \u001b[31m21.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
32-
"\u001b[?25h\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/2.4 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m147.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m38.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
33-
"\u001b[?25h"
34-
]
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"id": "VlZZgpHg4eo_",
150+
"metadata": {
151+
"id": "VlZZgpHg4eo_"
152+
},
153+
"outputs": [],
154+
"source": [
155+
"# Replace these paths with your own DICOM series paths\n",
156+
"ct_dicom_path = '/path/to/ct/dicom/series'\n",
157+
"mri_dicom_path = '/path/to/mri/dicom/series'\n",
158+
"\n",
159+
"ct_image = preprocess_dicom_series(ct_dicom_path, 'CT')\n",
160+
"mri_image = preprocess_dicom_series(mri_dicom_path, 'MRI')\n",
161+
"\n",
162+
"print('CT image shape:', ct_image.shape)\n",
163+
"print('MRI image shape:', mri_image.shape)"
164+
]
165+
}
166+
],
167+
"metadata": {
168+
"colab": {
169+
"provenance": []
170+
},
171+
"kernelspec": {
172+
"display_name": "Python 3",
173+
"language": "python",
174+
"name": "python3"
175+
},
176+
"language_info": {
177+
"name": "python",
178+
"version": "3.10"
35179
}
36-
],
37-
"source": [
38-
"# Install required packages\n",
39-
"!pip install monai pydicom nibabel --quiet"
40-
]
41-
},
42-
{
43-
"cell_type": "markdown",
44-
"id": "gyAtaTBP4eo7",
45-
"metadata": {
46-
"id": "gyAtaTBP4eo7"
47-
},
48-
"source": [
49-
"## Import Libraries"
50-
]
51-
},
52-
{
53-
"cell_type": "code",
54-
"execution_count": 5,
55-
"id": "k2DfCDZM4eo8",
56-
"metadata": {
57-
"id": "k2DfCDZM4eo8"
58-
},
59-
"outputs": [],
60-
"source": [
61-
"from monai.transforms import (\n",
62-
" LoadImage,\n",
63-
" EnsureChannelFirst,\n",
64-
" ScaleIntensityRange,\n",
65-
" NormalizeIntensity,\n",
66-
" Compose\n",
67-
")\n",
68-
"import numpy as np"
69-
]
70-
},
71-
{
72-
"cell_type": "markdown",
73-
"id": "HAxGJVgy4eo8",
74-
"metadata": {
75-
"id": "HAxGJVgy4eo8"
76-
},
77-
"source": [
78-
"## Define Preprocessing Pipelines"
79-
]
80-
},
81-
{
82-
"cell_type": "code",
83-
"execution_count": 6,
84-
"id": "cP-zDmqu4eo8",
85-
"metadata": {
86-
"id": "cP-zDmqu4eo8"
87-
},
88-
"outputs": [],
89-
"source": [
90-
"def get_ct_preprocessing_pipeline():\n",
91-
" return Compose([\n",
92-
" LoadImage(image_only=True),\n",
93-
" EnsureChannelFirst(),\n",
94-
" ScaleIntensityRange(a_min=-1000, a_max=400, b_min=0.0, b_max=1.0, clip=True)\n",
95-
" ])\n",
96-
"\n",
97-
"def get_mri_preprocessing_pipeline():\n",
98-
" return Compose([\n",
99-
" LoadImage(image_only=True),\n",
100-
" EnsureChannelFirst(),\n",
101-
" NormalizeIntensity(nonzero=True)\n",
102-
" ])"
103-
]
104-
},
105-
{
106-
"cell_type": "markdown",
107-
"id": "OuRHidt_4eo9",
108-
"metadata": {
109-
"id": "OuRHidt_4eo9"
110-
},
111-
"source": [
112-
"## Preprocessing Function"
113-
]
114-
},
115-
{
116-
"cell_type": "code",
117-
"execution_count": 7,
118-
"id": "BcGeKvkc4eo-",
119-
"metadata": {
120-
"id": "BcGeKvkc4eo-"
121-
},
122-
"outputs": [],
123-
"source": [
124-
"def preprocess_dicom_series(dicom_path, modality):\n",
125-
" modality = modality.upper()\n",
126-
" if modality == 'CT':\n",
127-
" transform = get_ct_preprocessing_pipeline()\n",
128-
" elif modality == 'MRI':\n",
129-
" transform = get_mri_preprocessing_pipeline()\n",
130-
" else:\n",
131-
" raise ValueError(\"Unsupported modality. Use 'CT' or 'MRI'.\")\n",
132-
" image = transform(dicom_path)\n",
133-
" return image"
134-
]
135-
},
136-
{
137-
"cell_type": "markdown",
138-
"id": "3bWBPrp44eo-",
139-
"metadata": {
140-
"id": "3bWBPrp44eo-"
141-
},
142-
"source": [
143-
"## Example Usage"
144-
]
145-
},
146-
{
147-
"cell_type": "code",
148-
"execution_count": null,
149-
"id": "VlZZgpHg4eo_",
150-
"metadata": {
151-
"id": "VlZZgpHg4eo_"
152-
},
153-
"outputs": [],
154-
"source": [
155-
"# Replace these paths with your own DICOM series paths\n",
156-
"ct_dicom_path = '/path/to/ct/dicom/series'\n",
157-
"mri_dicom_path = '/path/to/mri/dicom/series'\n",
158-
"\n",
159-
"ct_image = preprocess_dicom_series(ct_dicom_path, 'CT')\n",
160-
"mri_image = preprocess_dicom_series(mri_dicom_path, 'MRI')\n",
161-
"\n",
162-
"print('CT image shape:', ct_image.shape)\n",
163-
"print('MRI image shape:', mri_image.shape)"
164-
]
165-
}
166-
],
167-
"metadata": {
168-
"colab": {
169-
"provenance": []
170-
},
171-
"kernelspec": {
172-
"display_name": "Python 3",
173-
"language": "python",
174-
"name": "python3"
175180
},
176-
"language_info": {
177-
"name": "python",
178-
"version": "3.10"
179-
}
180-
},
181-
"nbformat": 4,
182-
"nbformat_minor": 5
181+
"nbformat": 4,
182+
"nbformat_minor": 5
183183
}

0 commit comments

Comments
 (0)