ThoracicLN-Stationer is an open-source thoracic lymph node stationing and mediastinal lymph node station segmentation tool for chest CT. It generates IASLC-style thoracic lymph node station masks, including stations 1L, 1R, 2L, 2R, 3A, 3P, 4L, 4R, 5, 6, 7, and 8.
The pipeline combines TotalSegmentator-derived anatomical structures, topology-aware bronchial branch parsing, anatomical plane generation, and rule-based spatial constraints to create station-wise NIfTI masks and 3D Slicer-compatible .seg.nrrd segmentations.
thoracic lymph node stationing; mediastinal lymph node station segmentation; IASLC lymph node map; chest CT lymph node station; CT-based lymph node station mapping; TotalSegmentator; 3D Slicer segmentation; rule-based medical image segmentation; anatomical plane-based segmentation; bronchial tree parsing.
ThoracicLN-Stationer is an anatomy-driven pipeline for thoracic lymph node station segmentation.
Unlike end-to-end black-box deep learning approaches, this project uses:
- TotalSegmentator-derived anatomical structures
- Topology-aware bronchial tree parsing
- Anatomical plane construction
- Rule-based spatial constraints
- IASLC-based lymph node station definitions
The goal is to produce interpretable thoracic lymph node station masks that are easier to inspect, modify, and validate in 3D Slicer.
This project is designed for:
- Thoracic lymph node station mapping
- Radiology AI preprocessing
- Anatomical atlas generation
- CT-based mediastinal region partitioning
- Rule-based interpretable segmentation workflows
Chest CT (.nii.gz)
↓
TotalSegmentator
↓
Anatomical structure extraction
↓
Bronchial tree extraction
↓
Topology-aware bronchial branch parsing
↓
Anatomical plane generation
↓
IASLC-based rule-defined station segmentation
↓
Post-processing
↓
Export:
Individual station masks (.nii.gz)
Combined station segmentation (.seg.nrrd, 3D Slicer compatible)
Thoracic lymph node stations are defined according to the International Association for the Study of Lung Cancer (IASLC) lymph node map.
Reference:
https://radiopaedia.org/articles/thoracic-lymph-node-stations
The station boundaries in this project are implemented using explicit anatomical landmarks and plane-based spatial rules derived from IASLC-style definitions.
This project uses TotalSegmentator for anatomical structure segmentation:
https://github.com/wasserth/TotalSegmentator
It also integrates my topology-aware bronchial tree parsing workflow:
The bronchial tree is first extracted from TotalSegmentator output, then parsed into anatomical branches using skeleton-based topology analysis. These bronchial landmarks are used as part of the station boundary logic.
The following image shows an example output of automated thoracic lymph node station segmentation:
The following video demonstrates the thoracic lymph node station parsing result and visualization in 3D Slicer.
🎥 YouTube demonstration:
https://youtu.be/yCSSgDmOnqA
Local demo video is also available in this repository:
To follow anatomical boundaries as precisely as possible, the full pipeline performs multiple segmentation, plane-generation, bronchial parsing, station-generation, and post-processing steps.
Typical processing time:
~18 minutes per case
The pipeline prioritizes anatomical precision, interpretability, and reproducibility over raw speed.
ThoracicLN-Stationer/
├── run.py
│
├── models/
│ └── Azygos.pth
│
├── Preprocess_script/
│ ├── Segmentator/
│ │ ├── AllSeg.py
│ │ ├── CavitySeg.py
│ │ ├── AzygosSeg.py
│ │ ├── LungVesselsSeg.py
│ │ ├── ExtractBronchialTree.py
│ │ └── bronchial_branch_labeler.py
│ │
│ └── Plane_script/
│ ├── RibPlane.py
│ ├── TracheaPlane.py
│ ├── TracheaPlane_LtLat.py
│ ├── TracheaPlane_Post.py
│ ├── AortaPlane.py
│ ├── AorticArchInfPlane.py
│ ├── LigamentumArteriosumPlane.py
│ ├── AzygosPlane.py
│ ├── LtCCAPlane.py
│ ├── SVCPlane.py
│ ├── HeartCentroidPlane.py
│ ├── HeartTopPlane.py
│ ├── CarinaPlane.py
│ ├── LLLPlane.py
│ └── BIPlane.py
│
├── LN_station_script/
│ ├── 1L.py
│ ├── 1R.py
│ ├── 2L.py
│ ├── 2R.py
│ ├── 3A.py
│ ├── 3P.py
│ ├── 4L.py
│ ├── 4R.py
│ ├── 5.py
│ ├── 6.py
│ ├── 7.py
│ └── 8.py
│
├── Postprocess_script/
│ ├── SubtractAll.py
│ ├── CombineName.py
│ └── ClearDoneFlags.py
│
└── LN_station_parser_Demo/
├── demo1.jpg
└── demo2.mp4
Each case should be placed in a patX folder:
pat1/
└── pat1_data.nii.gz
Example:
ThoracicLN-Stationer/
├── pat1/
│ └── pat1_data.nii.gz
├── pat2/
│ └── pat2_data.nii.gz
└── run.py
The GUI will automatically detect available pat* folders and locate the corresponding CT file.
Before running the pipeline, please download the pretrained Azygos inference model from Google Drive:
https://drive.google.com/file/d/1eSsBZOMtEF7L9Nx4k2FCRtiq0lhJAvd3/view?usp=drive_link
Place the downloaded model file into a folder named models:
ThoracicLN-Stationer/
├── models/
│ └── Azygos.pth
python run.pyThen:
- Select the patient folder, such as
pat1 - Confirm the CT path
- Click Run Pipeline
- Wait for the full pipeline to complete
The pipeline will automatically generate logs, intermediate masks, station masks, cleaned masks, and final Slicer-compatible output.
patX/intermediate/LN_station_temp/
Contains station-wise .nii.gz masks before subtraction cleanup.
patX/intermediate/LN_station_temp_cleaned/
Contains station-wise .nii.gz masks after subtracting segmented anatomical structures from TotalSegmentator output.
patX/LN_station/patX_LN_station.seg.nrrd
This file can be directly opened in 3D Slicer.
Each lymph node station is stored as an independent segment layer and named according to its station label:
1L
1R
2L
2R
3A
3P
4L
4R
5
6
7
8
The pipeline uses TotalSegmentator to derive key anatomical structures, including:
- Trachea
- Aorta
- Superior vena cava
- Heart
- Mediastinum
- Ribs
- Trunk cavities
- Lung vessels / airway-related structures
These structures serve as anatomical anchors for station definition.
Bronchial tree extraction and parsing are performed using a skeleton-based topology-aware method.
This provides branch-level anatomical landmarks such as:
- Trachea
- Main bronchi
- Bronchus intermedius
- LUL / LLL
- RUL / RML / RLL
- Segmental branches
These bronchial landmarks help define station boundaries that depend on airway anatomy.
The pipeline generates multiple anatomical planes, such as:
- Rib plane
- Carina plane
- Azygos plane
- Aorta plane
- Aortic arch inferior plane
- Ligamentum arteriosum plane
- SVC plane
- Heart top plane
- Heart centroid coronal plane
- Trachea lateral plane
- Trachea posterior plane
- LLL superior plane
- BI inferior plane
These planes are used as spatial boundaries for lymph node station segmentation.
Each thoracic lymph node station is generated using explicit rule-based constraints.
Examples:
- Superior and inferior boundaries are determined by anatomical planes
- Left/right boundaries are defined using tracheal, bronchial, and vascular landmarks
- Mediastinal fat or trunk-cavity masks provide the base candidate region
- Overlapping or non-target anatomical structures are subtracted during post-processing
The final result is interpretable because each step corresponds to an anatomical rule.
The pipeline generates stations including:
1L, 1R
2L, 2R
3A, 3P
4L, 4R
5, 6, 7, 8
Each station script is implemented separately in:
LN_station_script/
This makes it easier to inspect, debug, modify, or refine a specific station definition.
After station-wise segmentation, the pipeline performs:
- Anatomical structure subtraction
- Empty-mask filtering
- Segment renaming based on station filename
- Final
.seg.nrrdgeneration for 3D Slicer
The final segmentation is stored in:
patX/LN_station/
The included Tkinter GUI supports:
- Patient folder selection
- Automatic CT detection
- Manual CT selection
- Pipeline execution
- Step skipping using done flags
- Done-flag cleanup
- Runtime measurement
This makes the pipeline easier to run repeatedly during development and debugging.
- The pipeline is designed for research and development use.
- It depends on the quality of TotalSegmentator-derived masks.
- Extreme anatomical variation or poor CT quality may require manual inspection.
- Processing takes approximately 18 minutes per case because the pipeline prioritizes anatomical precision.
- The current implementation is rule-based and may require further validation before clinical use.
This project is intended for research and educational purposes only.
It is not a certified medical device and should not be used as the sole basis for clinical diagnosis, staging, or treatment planning.
MIT License
- TotalSegmentator for whole-body CT segmentation
- Kimimaro for skeletonization
- 3D Slicer for visualization and segmentation review
- Radiopaedia for thoracic lymph node station reference material
- IASLC lymph node station definitions
- Faster batch processing
- Improved handling of anatomical variants
- More robust QA visualization
- Quantitative station volume analysis
- Semi-automatic manual correction tools
- Integration with radiology AI workflows
