This project provides an automated pipeline to segment trunk muscles on CT, quantify intramuscular fat percentage (fat%), and evaluate correlations with thoracic kyphosis (Cobb angle). The workflow uses nnU-Net for segmentation, then computes fat% per muscle and Pearson correlations.
AtlasDataset (Jaus et al.) and TCIA CT-ORG (Rister et al.) are used in this study. Download them from the official sources:
AtlasDataset:
https://github.com/alexanderjaus/AtlasDataset
TCIA CT-ORG:
https://www.cancerimagingarchive.net/collection/ct-org/
Download the nnU-Net checkpoint from:
https://www.dropbox.com/scl/fi/8xlan84ziahyfoarfzzo5/checkpoint_best.pth?rlkey=2jq1ww1bghq6sip5w56khv8h1&st=rpqym6qv&dl=0
Place it at:
nnUNet_results/Dataset101_FinalSet/nnUNetTrainer__nnUNetPlans__3d_fullres/fold_all/checkpoint_best.pth
Create a Python environment and install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install torch nnunetv2 nibabel numpy pandas scipy
Set nnU-Net paths (from the repo root):
export nnUNet_raw=$(pwd)/nnUNet_raw
export nnUNet_preprocessed=$(pwd)/nnUNet_preprocessed
export nnUNet_results=$(pwd)/nnUNet_results
Input images should be NIfTI files with nnU-Net naming (e.g., case_0001_0000.nii.gz). Run prediction:
nnUNetv2_predict -i /path/to/images -o /path/to/labels_pred -d 101 -c 3d_fullres -f all -tr nnUNetTrainer -chk checkpoint_best.pth
After segmentation, use the simple inference script to compute fat% and Pearson correlations:
python inference.py --labels /path/to/labels_pred --images /path/to/images --cobb thoracic_cobb.txt --out-dir final_results
Outputs:
final_results/fat_inference.csvfinal_results/cobb_fat_pearson_inference.csv
inference.py expects a plain text Cobb file where line N corresponds to case ID N (1-indexed). Each line should contain a single numeric value (degrees). Missing or non-numeric values can be left blank or set to NA/nan.
Example (thoracic_cobb.txt):
38.2
41.0
NA
29.5
Case IDs are parsed from filenames/CSV rows by extracting the last numeric group (e.g., AtlasDataset_000123 → case 123). If your case numbering is different, either renumber the Cobb file to match or pass a dataset-specific Cobb file via --cobb.
If you need separate Cobb files for external or internal-test cohorts, use the scripts in scripts/:
python scripts/pearson_analysis.py --internal-fat-file final_results/internal_fat.csv --cobb-file thoracic_cobb.txt
python scripts/pearson_analysis.py --external-fat-file final_results/external_fat.csv --external-cobb-file thoracic_cobb_external.txt
nnUNet_raw/input dataset structurennUNet_results/model checkpoints and predictionsfinal_results/tables and analysis outputsscripts/utilities for fat% computation and correlation analysisinference.pysimplified end-to-end post-segmentation analysis