File size: 2,478 Bytes
b39edd1
 
3190965
b39edd1
3190965
 
b39edd1
3190965
b39edd1
 
3190965
 
 
 
 
b39edd1
3190965
b39edd1
3190965
 
 
 
 
b39edd1
3190965
 
 
 
 
 
 
 
 
 
 
b39edd1
 
3190965
b39edd1
3190965
b39edd1
3190965
 
 
 
 
 
 
 
 
 
b39edd1
 
3190965
 
 
 
 
 
f5c1710
3190965
 
 
 
 
 
 
 
 
 
 
 
 
 
b39edd1
3190965
b39edd1
3190965
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
## CT Binary Coronary Segmentation

Binary coronary artery segmentation from cardiac CT angiography (CCTA). Produces a binary vessel mask that can be used standalone or as input to the segmental coronary bundle.

**Architecture**: UNet [64,128,256,512], 1 input channel (CT), 2 output channels (background + vessel)
**Spacing**: 0.6 mm isotropic

### Quick Start (Inference)

```bash
# Download from HuggingFace
pip install huggingface_hub
huggingface-cli download kbressem/ct-heart-segmentation \
  --include "ct_binary_coronary_segmentation/**" \
  --local-dir ./

cd ct_binary_coronary_segmentation

# Single model (fold 0)
python -m monai.bundle run inference \
  --config_file configs/inference.yaml \
  --dataset_dir /path/to/ct_images \
  --output_dir /path/to/output

# 5-fold ensemble (recommended)
python -m monai.bundle run inference \
  --config_file configs/ensemble_inference.yaml \
  --dataset_dir /path/to/ct_images \
  --output_dir /path/to/output

# Use a specific fold
python -m monai.bundle run inference \
  --config_file configs/inference.yaml \
  --dataset_dir /path/to/ct_images \
  --fold 2
```

**Input**: Directory of CT images in NIfTI (`.nii`, `.nii.gz`), NRRD (`.nrrd`), or DICOM (`.dcm`) format.

**Output**: Per-image binary segmentation mask (NIfTI) resampled to original spacing, plus a `_centerline.json` file containing spline-smoothed vessel centerlines in physical (mm) coordinates.

### Requirements

```
monai>=1.3.0
torch>=2.0
scikit-image
scipy
pandas
psutil
itk
```

### Configuration Files

| File | Purpose |
|------|---------|
| `configs/inference.yaml` | Single-model inference |
| `configs/ensemble_inference.yaml` | 5-fold ensemble inference (best quality) |
| `configs/train.yaml` | Training config (requires local data manifest) |
| `configs/metadata.json` | Bundle metadata |

### Model Weights

5-fold cross-validation weights in `models/`:
- `ct_binary_coronary_segmentation_unet_fold_0.pt` through `fold_4.pt`

### Preprocessing Pipeline

```
LoadImaged (ITKReader) -> EnsureChannelFirstd -> Spacingd (0.6mm isotropic)
-> GaussianSmoothd (sigma=0.5) -> ApplyWindowingd (-100 to 900 HU)
-> ZScoreForegroundNormalized (threshold=-50)
```

### Scripts

- `scripts/transforms.py` - Custom transforms (windowing, normalization, centerline extraction)
- `scripts/utils.py` - Data loading and inference helpers
- `scripts/losses.py` - DiceclDiceLoss (Dice + centerline Dice)
- `scripts/meta.py` - Metadata preservation transforms