Skip to content

Commit 7c0748f

Browse files
authored
Merge pull request #31 from 1985312383/main
2 parents d1df69e + 0954430 commit 7c0748f

6 files changed

Lines changed: 25 additions & 159 deletions

File tree

docs/en/guide/ch05/01-preprocessing.md

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,6 @@ Medical image preprocessing can be divided into three levels:
4444
![Medical Image Preprocessing Hierarchy](/images/ch05/01-preprocessing-hierarchy-en.png)
4545
*Figure: Three levels of medical image preprocessing from basic to modality-specific to task-oriented.*
4646

47-
<details>
48-
<summary>📖 View Original Mermaid Code</summary>
49-
50-
```mermaid
51-
graph TD
52-
A[Raw Medical Images] --> B[Basic Preprocessing]
53-
B --> C[Modality-Specific Preprocessing]
54-
C --> D[Task-Oriented Preprocessing]
55-
56-
B --> B1[Resampling]
57-
B --> B2[Orientation Standardization]
58-
B --> B3[Size Adjustment]
59-
60-
C --> C1[CT: Windowing]
61-
C --> C2[MRI: Bias Correction]
62-
C --> C3[X-ray: Contrast Enhancement]
63-
64-
D --> D1[Data Augmentation]
65-
D --> D2[Normalization]
66-
D --> D3[Batch Balancing]
67-
```
68-
</details>
6947

7048
---
7149

@@ -136,7 +114,7 @@ def clip_hu_values(image, min_hu=-1000, max_hu=1000):
136114
return processed_image
137115
```
138116

139-
[📖 **Complete Code Example**: `clip_hu_values/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/clip_hu_values/) - Complete HU value clipping implementation, test cases and visualization demonstrations
117+
Full implementation: `src/ch05/clip_hu_values/`.
140118

141119
**Common Clipping Ranges:**
142120
- **Soft tissue range**: [-200, 400] HU (exclude air and dense bone)
@@ -167,7 +145,7 @@ def detect_metal_artifacts(image, threshold=3000):
167145
return significant_metal
168146
```
169147

170-
[📖 **Complete Code Example**: `detect_metal_artifacts/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/detect_metal_artifacts/) - Complete metal artifact detection algorithm, connectivity analysis and visualization functionality
148+
Full implementation: `src/ch05/detect_metal_artifacts/`.
171149

172150
### Practical Case: [Preparing CT imaging datasets for deep learning in lung nodule analysis: Insights from four well-known datasets](https://pmc.ncbi.nlm.nih.gov/articles/PMC10361226/pdf/main.pdf)
173151

@@ -210,7 +188,7 @@ This range encompasses:
210188
- Ground-glass nodules: HU < -300 (reduced attenuation)
211189
- Malignant lesions: Mean HU 30-50, maximum < 150
212190

213-
**[📖 Complete Code Example**: `clip_hu_values/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/clip_hu_values/) - HU value clipping with clinical validation]
191+
Full implementation for the clipping stage: `src/ch05/clip_hu_values/`.
214192

215193
##### **3. Lung Window and Contrast Enhancement**
216194

@@ -297,7 +275,7 @@ Within the segmented lung region, nodule candidates are identified and extracted
297275
- Connected-component analysis (size filtering)
298276
- Juxta-pleural nodule handling (specialized CNN for edge-attached nodules)
299277

300-
**[📖 Complete Code Example**: `medical_segmentation_augmentation/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/medical_segmentation_augmentation/) - Advanced segmentation with medical constraints]
278+
Full implementation for the segmentation-aware preprocessing stage: `src/ch05/medical_segmentation_augmentation/`.
301279

302280
##### **7. Normalization for Deep Learning**
303281

@@ -512,7 +490,7 @@ Bias Field Correction Statistics:
512490

513491
**Algorithm Analysis:** MRI bias field visualization estimates and displays bias field through multiple methods. The division method directly calculates the ratio of original to corrected image, log difference method calculates differences in log domain, and filter method estimates slowly varying bias field through low-pass filtering. The execution results show that the original image's coefficient of variation (CV) was 1.277, reduced to 0.972 after correction, a reduction of 23.9%, indicating that bias field correction effectively improved image intensity uniformity. The bias field mean is close to 1.0, conforming to theoretical expectations. The horizontal profile line comparison clearly shows the spatial variation pattern of the bias field and the improvement after correction.
514492

515-
[📖 **Complete Code Example**: `visualize_bias_field/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/visualize_bias_field/) - Complete MRI bias field estimation, multiple visualization methods and quantitative analysis functionality
493+
Full implementation: `src/ch05/visualize_bias_field/`.
516494

517495
### N4ITK Bias Field Correction Algorithm
518496

@@ -601,7 +579,7 @@ Correction Statistics:
601579

602580
**Algorithm Analysis:** N4ITK is a multi-scale iterative bias field correction method based on B-spline modeling. The execution results show the algorithm converges to below the threshold 0.001 after 20 iterations. The original image's coefficient of variation (CV) was 1.871, reduced to 1.493 after correction, an improvement of 20.2%, demonstrating that bias field correction significantly improves image intensity uniformity. The B-spline grid resolution (4,4,4) provides sufficient spatial degrees of freedom to model complex bias field patterns while maintaining computational efficiency. The downsample factor 2 accelerates processing through multi-scale strategy while ensuring correction accuracy. The bias field mean of 1.028 and std of 0.267 indicate a relatively smooth and stable bias field pattern.
603581

604-
[📖 **Complete Code Example**: `n4itk_bias_correction/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/n4itk_bias_correction/) - Complete N4ITK bias field correction implementation, test cases, synthetic data generation and visualization functionality
582+
Full implementation: `src/ch05/n4itk_bias_correction/`.
605583

606584
### White Stripe Intensity Normalization
607585

@@ -613,7 +591,7 @@ Correction Statistics:
613591
2. **Extract white matter intensity range**: Find the dominant mode of white matter through statistical analysis
614592
3. **Linear mapping**: Map white matter range to standard interval (e.g., [0, 1])
615593

616-
[📖 **Complete Code Example**: `white_stripe_normalization/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/) - Full White Stripe normalization implementation with multi-modality support]
594+
Full implementation: `src/ch05/white_stripe_normalization/`.
617595

618596
**Execution Results Analysis:**
619597

@@ -653,7 +631,7 @@ Normalization completed successfully!
653631

654632
**Algorithm Analysis:** White Stripe normalization identifies the white matter intensity peak through histogram analysis and uses it as a reference for intensity standardization. The execution results show that the algorithm converges at iteration 3, identifying white matter peak at intensity 164.2. White matter comprises 8.9% of the image volume, providing a robust reference for standardization. By mapping the white matter range [147.8, 180.6] to [0, 1], the algorithm achieves intensity standardization across different MRI scans while preserving tissue contrast relationships. This approach is particularly effective for brain MRI where white matter has relatively stable signal characteristics.
655633

656-
[📖 **Complete Code Example**: `white_stripe_normalization/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/white_stripe_normalization/) - Complete White Stripe normalization implementation with multi-modality support and intensity mapping verification
634+
Full implementation: `src/ch05/white_stripe_normalization/`.
657635

658636
### Multi-sequence MRI Fusion Strategies
659637

@@ -670,15 +648,14 @@ Different MRI sequences provide complementary tissue information:
670648

671649
![MRI Multi-sequence ](/images/ch05/MRI-BraTS2020.png)
672650
*Exemplary images depicting a WHO Grade IV Glioblastoma Multiforme (GBM) from the Multimodal Brain Tumor Segmentation Challenge (BraTS) 2020 dataset: Each row shows the axial, coronal and a sagittal view of each of the T1, T1CE, T2 and FLAIR sequences as well as the expert segmentation of the tumor (SEG): Necrotic core and non-enhancing tumor (center, dark grey), enhancing tumor (white, surrounding the necrotic core), peritumoral edema (light grey).*
673-
*Source: [Optimal acquisition sequence for AI-assisted brain tumor segmentation under the constraint of largest information gain per additional MRI sequence](https://www.sciencedirect.com/science/article/pii/S2772528622000152)*
674-
675651
![MRI2](/images/ch05/MRI2.png)
676-
*Sample images of the BrTMHD-2023 Dataset*
677-
*Source: [Brain tumor detection and classification in MRI using hybrid ViT and GRU model with explainable AI in Southern Bangladesh](https://www.nature.com/articles/s41598-024-71893-3)*
652+
*Sample images of the BrTMHD-2023 Dataset.*
653+
654+
*Sources for the MRI sequence figures: the information-gain study for the BraTS example, and the BrTMHD classification paper for the sample MRI panel.*
678655

679656
#### Multi-sequence Fusion Methods
680657

681-
[📖 **Complete Code Example**: `multisequence_fusion/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/) - Multi-sequence MRI fusion implementation with different strategies]
658+
Full implementation: `src/ch05/multisequence_fusion/`.
682659

683660
**Execution Results Analysis:**
684661

@@ -1017,35 +994,6 @@ def elastic_transform_3d(image, alpha, sigma, order=1):
1017994
![Task-driven Preprocessing Strategy](/images/ch05/02-preprocessing-strategy-en.png)
1018995
*Figure: Decision flow for selecting appropriate preprocessing strategies based on imaging modality.*
1019996

1020-
<details>
1021-
<summary>📖 View Original Mermaid Code</summary>
1022-
1023-
```mermaid
1024-
flowchart TD
1025-
A[Medical Image Preprocessing Task] --> B{Determine Imaging Modality}
1026-
1027-
B -->|CT| C[HU Value Calibration]
1028-
C --> D[Window Level Adjustment]
1029-
D --> E[Outlier Processing]
1030-
1031-
B -->|MRI| F[Bias Field Correction]
1032-
F --> G[Intensity Standardization]
1033-
G --> H[Multi-sequence Fusion]
1034-
1035-
B -->|X-ray| I[Contrast Enhancement]
1036-
I --> J[Anatomical Region Segmentation]
1037-
J --> K[Local Normalization]
1038-
1039-
E --> L[Universal Preprocessing]
1040-
H --> L
1041-
K --> L
1042-
1043-
L --> M[Resampling]
1044-
M --> N[Size Standardization]
1045-
N --> O[Data Augmentation]
1046-
O --> P[Final Normalization]
1047-
```
1048-
</details>
1049997

1050998
### Common Pitfalls and Solutions
1051999

@@ -1105,7 +1053,7 @@ def validate_preprocessing(original_image, processed_image, roi_mask=None):
11051053

11061054
## 🖼️ Algorithm Demonstrations
11071055

1108-
Below we showcase the practical effects of our implemented preprocessing algorithms on real data. All code examples can be found and run in the [`ch05-code-examples`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/) directory.
1056+
Below we showcase the practical effects of our implemented preprocessing algorithms on real data. Full runnable examples are grouped under `src/ch05/`.
11091057

11101058
### MRI Bias Field Visualization and Correction
11111059

docs/en/guide/ch05/02-segmentation.md

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -47,61 +47,6 @@ Let's deeply understand U-Net's network structure and data flow:
4747
![U-Net Architecture Deep Dive](/images/ch05/03-unet-architecture-en.png)
4848
*Figure: U-Net's encoder-decoder structure showing how skip connections transfer shallow features to deep layers to preserve spatial details.*
4949

50-
<details>
51-
<summary>📖 View Original Mermaid Code</summary>
52-
53-
```mermaid
54-
graph TD
55-
subgraph "Encoder Path (Contracting Path)"
56-
A[Input: 512×512×1] --> B[Conv3×3+ReLU ×2]
57-
B --> C[64 channels]
58-
C --> D[MaxPool2×2]
59-
D --> E[Conv3×3+ReLU ×2]
60-
E --> F[128 channels]
61-
F --> G[MaxPool2×2]
62-
G --> H[Conv3×3+ReLU ×2]
63-
H --> I[256 channels]
64-
I --> J[MaxPool2×2]
65-
J --> K[Conv3×3+ReLU ×2]
66-
K --> L[512 channels]
67-
L --> M[MaxPool2×2]
68-
M --> N[Conv3×3+ReLU ×2]
69-
N --> O[1024 channels]
70-
end
71-
72-
subgraph "Decoder Path (Expanding Path)"
73-
O --> P[Up-Conv2×2]
74-
L --> P
75-
P --> Q[Concat: 1024+512=1536]
76-
Q --> R[Conv3×3+ReLU ×2]
77-
R --> S[512 channels]
78-
S --> T[Up-Conv2×2]
79-
I --> T
80-
T --> U[Concat: 512+256=768]
81-
U --> V[Conv3×3+ReLU ×2]
82-
V --> W[256 channels]
83-
W --> X[Up-Conv2×2]
84-
F --> X
85-
X --> Y[Concat: 256+128=384]
86-
Y --> Z[Conv3×3+ReLU ×2]
87-
Z --> AA[128 channels]
88-
AA --> AB[Up-Conv2×2]
89-
C --> AB
90-
AB --> AC[Concat: 128+64=192]
91-
AC --> AD[Conv3×3+ReLU ×2]
92-
AD --> AE[64 channels]
93-
AE --> AF[Conv1×1]
94-
AF --> AG[Output: Segmentation Map]
95-
end
96-
97-
style A fill:#E8F8F5
98-
style AG fill:#FADBD8
99-
100-
classDef skip fill:#F9F,stroke:#333,stroke-width:2px;
101-
linkStyle 7,11,15,19 stroke-width:2px,fill:none,stroke:blue,stroke-dasharray: 5 5;
102-
```
103-
104-
</details>
10550

10651
### Detailed Analysis of Key Components
10752

@@ -300,35 +245,8 @@ The original U-Net's skip connections might not be fine enough; U-Net++ improves
300245

301246
**Dense Skip Connections**: Establish connections between decoder layers at different depths
302247

303-
```mermaid
304-
graph TD
305-
A[Input] --> B[Encoder L1]
306-
B --> C[Encoder L2]
307-
C --> D[Encoder L3]
308-
D --> E[Encoder L4]
309-
310-
E --> F[Decoder L4]
311-
D --> F
312-
C --> F
313-
B --> F
314-
315-
F --> G[Decoder L3]
316-
D --> G
317-
C --> G
318-
B --> G
319-
320-
G --> H[Decoder L2]
321-
C --> H
322-
B --> H
323-
324-
H --> I[Decoder L1]
325-
B --> I
326-
327-
I --> J[Output]
328-
329-
classDef dense stroke:#f66,stroke-width:2px;
330-
linkStyle 5,6,7,8,9,10,11,12,13,14 stroke:#f66,stroke-width:2px;
331-
```
248+
![U-Net++ Dense Skip Connections](/images/ch05/04-unet-plus-plus-en.png)
249+
*Figure: U-Net++ replaces one-step skip fusion with denser intermediate pathways, making encoder and decoder features easier to align.*
332250

333251
**U-Net++ advantages:**
334252

@@ -640,7 +558,7 @@ def medical_segmentation_augmentation(image, mask):
640558
return image, mask
641559
```
642560

643-
[📖 **Complete Code Example**: `medical_segmentation_augmentation/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/medical_segmentation_augmentation/) - Complete medical image segmentation augmentation implementation with multiple augmentation strategies and clinical validation
561+
Full implementation: `src/ch05/medical_segmentation_augmentation/`.
644562

645563
### Medical Image Segmentation Augmentation Demonstration
646564

docs/en/guide/ch05/04-enhancement.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The field of medical imaging faces unique challenges: data scarcity, variations
2121

2222
Geometric transformations for medical images require special consideration, as anatomical spatial relationships cannot be arbitrarily altered:
2323

24-
[📖 **Complete Code Example**: `data_augmentation/`](https://github.com/datawhalechina/med-imaging-primer/tree/main/src/ch05/) - Complete medical image augmentation implementation, 2D/3D transformations, and modality adaptation]
24+
Full implementation: `src/ch05/medical_image_augmentation/`.
2525

2626
**Execution Results Analysis:**
2727

docs/zh/guide/ch05/01-preprocessing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def clip_hu(image, hu_min=-1000, hu_max=1000):
101101

102102
- **输入**:原始 CT 体数据,单位仍是 HU。
103103
- **输出**:截断后的 CT 数据,便于后续归一化或窗化。
104-
- **完整实现**`src/ch05/clip_hu_values/main.py`
104+
- 完整实现见 `src/ch05/clip_hu_values/`
105105

106106
### 2. 重采样:先算缩放比例,再统一体素间距
107107
```python
@@ -116,7 +116,7 @@ def scale_factors(original_spacing, target_spacing):
116116

117117
- **输入**:如 `(0.7, 0.7, 5.0)` 的原始 spacing。
118118
- **输出**:对应目标 spacing 的缩放因子。
119-
- **完整实现**`src/ch05/medical_image_resampling/main.py`
119+
- 完整实现见 `src/ch05/medical_image_resampling/`
120120

121121
### 3. MRI:用白质带做强度标准化
122122
```python
@@ -132,7 +132,7 @@ def normalize_with_white_stripe(image, wm_mask):
132132

133133
- **输入**:MRI 图像与白质区域掩膜或其近似估计。
134134
- **输出**:组织间更可比的标准化结果。
135-
- **完整实现**`src/ch05/white_stripe_normalization/main.py`
135+
- 完整实现见 `src/ch05/white_stripe_normalization/`
136136

137137
### 4. 金属伪影:先做一个高阈值检测
138138
```python
@@ -143,7 +143,7 @@ def detect_metal(image, threshold=3000):
143143

144144
- **输入**:CT 图像。
145145
- **输出**:疑似金属区域的布尔掩膜。
146-
- **完整实现**`src/ch05/detect_metal_artifacts/main.py`,其中还包含连通域筛选和可视化
146+
- 完整实现见 `src/ch05/detect_metal_artifacts/`
147147

148148
---
149149

docs/zh/guide/ch05/02-segmentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def double_conv(in_channels, out_channels):
100100

101101
- **输入**:某一层特征图。
102102
- **输出**:通道数增加、局部表征更强的特征图。
103-
- **完整实现**`src/ch05/lung_segmentation_network/main.py`
103+
- 完整实现见 `src/ch05/lung_segmentation_network/`
104104

105105
### 2. 跳跃连接的关键动作:拼接
106106
```python
@@ -128,7 +128,7 @@ def dice_score(pred_mask, true_mask, eps=1e-6):
128128

129129
- **输入**:预测掩膜与真值掩膜。
130130
- **输出**`0~1` 的重叠度量。
131-
- **完整评估与报告**`src/ch05/lung_segmentation_network/main.py` 及其 `output/` 结果文件
131+
- 完整训练、评估与结果导出见 `src/ch05/lung_segmentation_network/`
132132

133133
---
134134

docs/zh/guide/ch05/04-enhancement.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def small_rotation(image, angle=5):
9191

9292
- **输入**:单张医学图像。
9393
- **输出**:小角度旋转后的图像。
94-
- **完整实现**`src/ch05/medical_image_augmentation/simple_augmentation.py`
94+
- 完整实现见 `src/ch05/medical_image_augmentation/`
9595

9696
### 2. 一个最小的强度扰动片段
9797
```python
@@ -119,7 +119,7 @@ def run_clahe(image, clip_limit=2.0, tile_grid_size=(8, 8)):
119119

120120
- **输入**:8-bit 灰度图像。
121121
- **输出**:局部对比度增强后的图像。
122-
- **完整实现**`src/ch05/clahe_enhancement/main.py`
122+
- 完整实现见 `src/ch05/clahe_enhancement/`
123123

124124
---
125125

0 commit comments

Comments
 (0)