Skip to main content

Automated pelvimetry and body composition analysis from CT segmentations

Project description

ctpelvimetry

PyPI version Python versions License

The first open-source Python package for fully automated CT pelvimetry and body composition analysis.

Automatically measure pelvic dimensions and body composition from CT images — no manual annotation required. Integrates with TotalSegmentator for segmentation and provides a complete DICOM-to-results pipeline.

pip install ctpelvimetry

Why ctpelvimetry?

  • Fully automated — from DICOM to structured results in one command, no manual landmark placement
  • Reproducible — eliminates inter-observer variability inherent in manual CT pelvimetry
  • Batch-ready — process hundreds of patients with progress tracking and failure summaries
  • Quality-controlled — automatic detection of pelvic rotation, tilt, and sacrum offset with QC figures
  • Modular — use the full pipeline or individual analysis functions via CLI or Python API

Features

Pelvimetry Measurements

Metric Description
ISD (mm) Inter-Spinous Distance
APD (mm) Antero-Posterior Diameter at ISD level
Inlet AP (mm) Promontory → Upper Symphysis
Outlet AP (mm) Coccygeal Apex → Lower Symphysis
Outlet Transverse (mm) Intertuberous diameter
Outlet Area (cm²) Ellipse approx: π/4 × AP × Transverse
Sacral Length (mm) Promontory → Coccygeal Apex
Sacral Depth (mm) Max anterior concavity

Body Composition Measurements

Metric Description
VAT (cm²) Visceral Adipose Tissue area
SAT (cm²) Subcutaneous Adipose Tissue area
V/S ratio VAT / SAT ratio
SMA (cm²) Skeletal Muscle Area

Measured at L3 vertebral level and ISD (mid-pelvis) level.

Key Features

  • Per-metric error isolation — failure in one metric does not affect the others
  • Quality gates — automatic detection of pelvic rotation, tilt, and sacrum offset
  • Batch processing — process hundreds of patients with progress tracking and failure summaries
  • QC figures — sagittal combined, extended 3-panel, and body composition overlays
  • Modular design — use the full pipeline or individual analysis functions

QC Output Example

QC Example — Sagittal pelvimetry with automated landmark detection

Sagittal QC figure showing automated landmark detection and pelvimetric measurements: sacral length (magenta), inlet AP (green), outlet AP (orange), and sacral depth (cyan).

Extended QC Example — Axial views with measurement summary

Extended QC panel: (a) outlet transverse diameter at tuberosity level, (b) interspinous distance on axial view, and (c) complete pelvimetry measurement summary.

Installation

# Basic install (analyse existing segmentations)
pip install ctpelvimetry

# Full install (includes TotalSegmentator for segmentation)
pip install "ctpelvimetry[seg]"

Note: The full install pulls in TotalSegmentator and its PyTorch dependencies. If you only need to analyse pre-existing segmentations, the basic install is sufficient.

Dependencies

Package Minimum Version
numpy ≥ 1.24
nibabel ≥ 5.0
pandas ≥ 2.0
scipy ≥ 1.11
matplotlib ≥ 3.7
tqdm ≥ 4.60
TotalSegmentator ≥ 2.0 (optional, pip install ".[seg]")

Usage Examples

CLI — Pelvimetry (from existing segmentation)

ctpelvimetry pelv \
  --seg_folder /path/to/segmentations \
  --nifti_path /path/to/ct.nii.gz \
  --patient Patient_001 \
  --output_root ./output --qc

CLI — Full Pipeline (DICOM → NIfTI → Seg → Measurements)

ctpelvimetry pelv \
  --dicom_dir /path/to/Patient_001 \
  --output_root ./output \
  --patient Patient_001

CLI — Body Composition

ctpelvimetry body-comp \
  --patient Patient_001 \
  --seg_root ./batch_output \
  --nifti_root ./batch_output \
  --pelvimetry_csv ./batch_output/combined_pelvimetry_report.csv \
  --output body_comp.csv --qc

CLI — Batch Processing

# Pelvimetry batch
ctpelvimetry pelv \
  --dicom_root /path/to/DICOMs \
  --output_root ./output \
  --start 1 --end 250

# Body composition batch
ctpelvimetry body-comp \
  --seg_root ./batch_output \
  --nifti_root ./batch_output \
  --pelvimetry_csv ./report.csv \
  --output body_comp.csv \
  --start 1 --end 210 --qc_root ./qc

Python API

from ctpelvimetry import run_combined_pelvimetry, process_single_patient

# Pelvimetry
result = run_combined_pelvimetry(
    "Patient_001", "/path/to/seg", "/path/to/ct.nii.gz"
)

# Body composition
result = process_single_patient(
    "Patient_001", "/path/to/seg_root",
    "/path/to/ct.nii.gz", "/path/to/report.csv"
)

Package Structure

ctpelvimetry/
├── __init__.py          # Public API
├── config.py            # PelvicConfig, constants
├── io.py                # Mask loading, coordinate transforms
├── conversion.py        # DICOM → NIfTI (dcm2niix)
├── segmentation.py      # TotalSegmentator execution
├── landmarks.py         # Midline, symphysis, sacral landmarks
├── metrics.py           # ISD, APD, ITD, sacral depth
├── body_composition.py  # VAT/SAT/SMA analysis
├── qc.py                # QC figure generation
├── pipeline.py          # run_combined_pelvimetry, run_full_pipeline
├── batch.py             # Batch orchestration
└── cli.py               # Unified CLI entry point

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m "Add your feature")
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a Pull Request

Citation

If you use ctpelvimetry in your research, please cite:

@software{huang2025ctpelvimetry,
  author    = {Huang, Shih-Feng},
  title     = {ctpelvimetry: Automated CT Pelvimetry and Body Composition Analysis},
  year      = {2025},
  url       = {https://github.com/odafeng/ctpelvimetry},
  version   = {1.1.0}
}

A peer-reviewed manuscript describing ctpelvimetry is currently in preparation. Citation details will be updated upon publication.

License

This project is licensed under the Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctpelvimetry-1.1.1.tar.gz (48.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctpelvimetry-1.1.1-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file ctpelvimetry-1.1.1.tar.gz.

File metadata

  • Download URL: ctpelvimetry-1.1.1.tar.gz
  • Upload date:
  • Size: 48.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ctpelvimetry-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2367c2d653c806f0fe3eabe3657276fb29d828c4470054fb5b5d543e6a9c2356
MD5 41cb4f2db1e1bd53a411e67f452ded7d
BLAKE2b-256 a648e631fea84a2f34e949cdb8a156fdaa3f3f7f751edf0f0b4f02fa1578c30b

See more details on using hashes here.

File details

Details for the file ctpelvimetry-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: ctpelvimetry-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 45.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ctpelvimetry-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e34d59cc5d47053b0375a429991ab32d4a9057bd7fe6841cd3381d02e0da92a
MD5 9a7309858d0fe041d384297d19d50fee
BLAKE2b-256 0d2f97f725797ae28615a3836b72b0e86facfb53bb050fb46492c50072b1500c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page