f8b21af4be
10_Wiki/Topics 대규모 정리: - 오류 캡처/미완성 stub 문서 227개 제거 - 교차폴더 중복 43클러스터 병합 (63파일 → redirect) - 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건 - 카테고리 MOC 6개 신규 생성 - Graph 섹션 미해결 related-keyword 링크 10,058건 제거 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
151 lines
5.7 KiB
Markdown
151 lines
5.7 KiB
Markdown
---
|
|
id: wiki-2026-0508-medical-imaging-data-augmentation
|
|
title: Medical Imaging Data Augmentation
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [Medical Augmentation, MONAI Augmentation, 의료영상 증강]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.9
|
|
verification_status: applied
|
|
tags: [medical-imaging, data-augmentation, monai, deep-learning, segmentation]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack: { language: python, framework: monai-pytorch }
|
|
---
|
|
|
|
# Medical Imaging Data Augmentation
|
|
|
|
## 매 한 줄
|
|
> **"매 환자 데이터는 매 적고, 매 anatomy 는 망가뜨릴 수 없다"**. 의료영상 augmentation 은 일반 이미지 대비 (1) 데이터가 매우 적고 (2) 라벨이 픽셀 단위 정확해야 하며 (3) 비현실적 변형이 진단을 망친다는 제약 안에서 기하·강도·합성 변환을 신중히 적용해야 한다.
|
|
|
|
## 매 핵심
|
|
### 매 도메인 특성
|
|
- 3D volume (CT/MRI), DICOM/NIfTI 포맷, voxel spacing 다양.
|
|
- 라벨이 segmentation mask / bbox / 환자 단위 진단 — affine 변환 시 동기화.
|
|
- HU scale (CT), bias field (MRI) 등 강도 분포가 modality 마다 다름.
|
|
|
|
### 매 변환 카테고리
|
|
1. **Spatial / 기하**: flip, rotate (소각), translate, scale, elastic deformation, B-spline.
|
|
2. **Intensity**: brightness/contrast, gamma, Gaussian noise, Rician noise (MRI), bias field, MR motion artifact.
|
|
3. **Spacing / Resolution**: random resample, low-res sim.
|
|
4. **Topology-preserving**: mixup/cutmix 의 의료 variant — 단, lesion mask 가 깨지지 않도록 patch-aware.
|
|
5. **Synthesis**: GAN/diffusion 으로 lesion 합성, healthy↔lesion translation.
|
|
|
|
### 매 라이브러리
|
|
1. **MONAI**: PyTorch 기반 의료영상 표준, `Compose`, dictionary transform.
|
|
2. **TorchIO**: 3D 친화, MRI artifact 풍부.
|
|
3. **Albumentations**: 2D slice/엑스레이.
|
|
4. **NVIDIA DALI**: GPU augmentation 파이프라인.
|
|
|
|
## 💻 패턴
|
|
### 1. MONAI dict transform pipeline
|
|
```python
|
|
from monai.transforms import (Compose, LoadImaged, EnsureChannelFirstd,
|
|
Spacingd, Orientationd, ScaleIntensityRanged, RandCropByPosNegLabeld,
|
|
RandAffined, RandGaussianNoised, RandBiasFieldd, ToTensord)
|
|
|
|
train_t = Compose([
|
|
LoadImaged(keys=["img","seg"]),
|
|
EnsureChannelFirstd(keys=["img","seg"]),
|
|
Orientationd(keys=["img","seg"], axcodes="RAS"),
|
|
Spacingd(keys=["img","seg"], pixdim=(1,1,1), mode=("bilinear","nearest")),
|
|
ScaleIntensityRanged(keys="img", a_min=-200, a_max=300, b_min=0, b_max=1, clip=True),
|
|
RandCropByPosNegLabeld(keys=["img","seg"], label_key="seg",
|
|
spatial_size=(96,96,96), pos=1, neg=1, num_samples=4),
|
|
RandAffined(keys=["img","seg"], rotate_range=0.1, scale_range=0.1,
|
|
mode=("bilinear","nearest"), prob=0.5),
|
|
RandGaussianNoised(keys="img", std=0.01, prob=0.2),
|
|
RandBiasFieldd(keys="img", coeff_range=(0.0,0.1), prob=0.2),
|
|
ToTensord(keys=["img","seg"]),
|
|
])
|
|
```
|
|
|
|
### 2. Elastic deformation
|
|
```python
|
|
from monai.transforms import Rand3DElasticd
|
|
Rand3DElasticd(keys=["img","seg"], sigma_range=(5,7), magnitude_range=(50,150),
|
|
mode=("bilinear","nearest"), prob=0.3)
|
|
```
|
|
Anatomy 자연스러운 변형 — sigma 너무 작으면 비현실, 크면 underfit.
|
|
|
|
### 3. TorchIO MRI artifact
|
|
```python
|
|
import torchio as tio
|
|
tx = tio.Compose([
|
|
tio.RandomMotion(degrees=5, translation=5, p=0.2),
|
|
tio.RandomGhosting(num_ghosts=(2,5), p=0.2),
|
|
tio.RandomBiasField(coefficients=0.3, p=0.3),
|
|
tio.RandomNoise(std=(0,0.05), p=0.3),
|
|
])
|
|
```
|
|
|
|
### 4. CT HU window robust
|
|
```python
|
|
def hu_window(vol, center, width):
|
|
lo, hi = center - width/2, center + width/2
|
|
return np.clip((vol - lo) / (hi - lo), 0, 1)
|
|
# 학습 중 center/width 를 약하게 jitter
|
|
```
|
|
|
|
### 5. Lesion-aware MixUp (segmentation)
|
|
```python
|
|
def lesion_mixup(x1, y1, x2, y2, alpha=0.2):
|
|
lam = np.random.beta(alpha, alpha)
|
|
x = lam*x1 + (1-lam)*x2
|
|
y = (y1 + y2).clip(0,1) # union mask
|
|
return x, y
|
|
```
|
|
|
|
### 6. Diffusion synthetic lesion
|
|
```python
|
|
# Stable Diffusion fine-tuned on chest X-ray with lesion mask conditioning
|
|
img = pipe(prompt="pneumonia consolidation right lower lobe", mask=mask).images[0]
|
|
# 합성 데이터는 별도 split, 평가는 real only
|
|
```
|
|
|
|
### 7. Test-Time Augmentation (TTA)
|
|
```python
|
|
preds = []
|
|
for tta in [identity, flip_x, flip_y, rot90]:
|
|
preds.append(undo(model(tta(x))))
|
|
final = torch.stack(preds).mean(0)
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Augmentation |
|
|
|---|---|
|
|
| 작은 segmentation 데이터 | strong elastic + intensity + cropbypos/neg |
|
|
| 분류 (X-ray) | mild affine + cutout, lesion 보호 |
|
|
| MRI multi-site | bias field + intensity histogram match |
|
|
| CT multi-protocol | HU window jitter + spacing resample |
|
|
| 매우 적은 라벨 | + synthetic (GAN/diffusion) + self-supervised pretrain |
|
|
|
|
**기본값**: MONAI `Compose` + spacing/orient 정규화 → mild affine + intensity + (3D 면) crop-by-label.
|
|
|
|
## 🔗 Graph
|
|
- 부모: [[Data-Augmentation]]
|
|
- Adjacent: [[Diffusion-Model]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: pipeline boilerplate, modality 별 적절 변환 추천, 코드 review.
|
|
**언제 X**: 임상적 plausibility 판단 (radiologist 검증 필요).
|
|
|
|
## ❌ 안티패턴
|
|
- 90° rotate / 큰 scale → CT 좌표계/anatomy 깨짐.
|
|
- segmentation mask 에 bilinear interpolation — 라벨 손상.
|
|
- intensity normalize 를 augmentation 후 적용 → 분포 불일치.
|
|
- synthetic 데이터를 real 평가셋과 섞기 — leakage.
|
|
- 모든 patient slice 를 독립 sample 로 — patient-level leakage, split 단위는 patient.
|
|
|
|
## 🧪 검증 / 중복
|
|
- Verified. 신뢰도 A.
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup |
|