How wasserth/totalsegmentator works
TotalSegmentator is a CT/MR anatomical segmentation and quantitative reporting toolkit. The principal workflow accepts NIfTI or DICOM input, converts and preprocesses it, selects a configured task, runs nnUNet models, postprocesses masks, and writes segmentation outputs and optional statistics. Separate report pipelines derive aorta, pulmonary, and spine measurements. The MCP server exposes task discovery and command execution. Core orchestration and several report internals were inferred from documented paths and sampled excerpts; unsampled wiring is shown conservatively.
Main entry points: python_api.py Python API · mcp_server.py MCP Server · TotalSegmentator.py CLI Commands · nnunet.py nnUNet Runtime
Components 24
Interfaces
- CLI Commands
totalsegmentator/bin/TotalSegmentator.py - MCP Server
totalsegmentator_mcp/mcp_server.py - Task Registry
totalsegmentator/registry.py - Python API
totalsegmentator/python_api.py
Input Preparation
- DICOM Conversion
totalsegmentator/dicom_io.py - Resampling
totalsegmentator/resampling.py - ROI Cropping
totalsegmentator/cropping.py - Task Configuration
totalsegmentator/map_tasks_config.py
Segmentation Inference
- nnUNet Runtime
totalsegmentator/nnunet.py - Model Runner
totalsegmentator/cnn.py - Mask Postprocessing
totalsegmentator/postprocessing.py - Class Mapping
totalsegmentator/map_to_binary.py
Outputs And Stats
- Segmentation Files
totalsegmentator/serialization_utils.py - Statistics
totalsegmentator/statistics.py - Body Statistics
totalsegmentator/bin/totalseg_get_body_stats.py - 3D Preview
totalsegmentator/preview.py
Quantitative Reports
- Aorta Pipeline
totalsegmentator/aorta_report/pipeline.py - Aorta Measurements
totalsegmentator/aorta_report/measurements.py - Aorta Report
totalsegmentator/aorta_report/rendering.py - Pulmonary Pipeline
totalsegmentator/pulmonary_report/pipeline.py - Pulmonary Report
totalsegmentator/pulmonary_report/rendering.py - Spine Report
totalsegmentator/spine_report/measure_verte_height.py
Other components
- User Or System
- Model Weights
Connections 28
- User Or System → CLI Commands: invokes
- User Or System → MCP Server: requests
- CLI Commands → Python API: calls
- CLI Commands → Task Registry: reads tasks
- MCP Server → Task Registry: queries
- MCP Server → CLI Commands: runs commands
- MCP Server → Body Statistics: runs stats
- Python API → DICOM Conversion: converts input
- Python API → Task Configuration: selects task
- Python API → Resampling: resamples image
- Python API → ROI Cropping: crops regions
- Python API → Model Runner: runs models
- Task Configuration → nnUNet Runtime: configures inference
- Model Runner → nnUNet Runtime: invokes runtime
- Model Weights → nnUNet Runtime: provides weights
- nnUNet Runtime → Mask Postprocessing: returns masks
- Mask Postprocessing → Class Mapping: maps classes
- Python API → Segmentation Files: writes masks
- Python API → Statistics: calculates stats
- Statistics → Segmentation Files: writes statistics
- Body Statistics → Statistics: computes measurements
- Python API → 3D Preview: renders preview
- Aorta Pipeline → Model Runner: runs segmentation
- Aorta Pipeline → Aorta Measurements: measures anatomy
- Aorta Measurements → Aorta Report: builds report
- Pulmonary Pipeline → Model Runner: runs segmentation
- Pulmonary Pipeline → Pulmonary Report: builds report
- Spine Report → Segmentation Files: reads masks