This project provides a pipeline for automatic CT phase and subphase classification using organ segmentation, radiomics feature extraction, and trained machine learning models.
The pipeline first predicts one of the main CT contrast phases:
- NP: Non-Contrast Phase
- AP: Arterial Phase
- VP: Portal-Venous Phase
- DP: Delayed Phase
If the scan is predicted as AP, an additional submodel is used to classify the scan as:
- EAP: Early Arterial Phase
- LAP: Late Arterial Phase
If the scan is predicted as VP, another submodel is used to classify the scan as:
- VP: Portal-Venous Phase
- NEP: Nephrographic Phase
Scans predicted as NP or DP are returned directly without further subphase classification.
The pipeline consists of the following steps:
- Read a CT image from a DICOM folder or a NIfTI file.
- Segment selected anatomical structures using TotalSegmentator.
- Extract radiomic features from the segmentation masks using PyRadiomics.
- Prepare the extracted features so they match the selected features used during training.
- Predict the main CT phase using the main classification model.
- Apply a subphase classifier if the main phase is predicted as AP or VP.
The following anatomical structures are used for feature extraction:
- Aorta
- Portal vein and splenic vein
- Urinary bladder
- Kidneys
- Spleen
- Liver
-
feature_extractor.py
Runs TotalSegmentator and extracts radiomic features from the selected anatomical structures. -
phase_pipeline.py
Runs the full hierarchical prediction pipeline and returns the final CT phase prediction. -
requirements.txt
Contains the Python packages needed to run the project. -
final_models/
Folder containing the trained models, selected feature lists, and label encoders.
This project requires Python 3.10 or 3.11.
Install the required packages using:
pip install -r requirements.txtThe main packages used in this project are:
- TotalSegmentator
- PyRadiomics
- SimpleITK
- pandas
- scikit-learn
- XGBoost
- joblib
Run the pipeline from the command line:
python phase_pipeline.py "input_path"The input_path can be either:
- a DICOM folder
- a NIfTI file, for example
.nii.gz
Example:
python phase_pipeline.py "path/to/ct_scan.nii.gz"or:
python phase_pipeline.py "path/to/dicom_folder"Use the fast TotalSegmentator option:
python phase_pipeline.py "input_path" --fastUse a local TotalSegmentator model directory:
python phase_pipeline.py "input_path" --totalseg-model-dir "path/to/totalseg_models"Save the extracted features to a CSV file:
python phase_pipeline.py "input_path" --save-features extracted_features.csvUse a custom model directory:
python phase_pipeline.py "input_path" --model-dir "path/to/final_models"The pipeline prints:
- the main phase prediction
- the final predicted phase
- the submodel used, if applicable
- class probabilities when available
If --save-features is used, the extracted features are also saved as a CSV file.
- TotalSegmentator: https://github.com/wasserth/TotalSegmentator
- PyRadiomics: https://pyradiomics.readthedocs.io/
