Tool for automatic segmentation and labelling of all vertebrae and intervertebral discs (IVDs), spinal cord, and spinal canal. We follow TotalSegmentator classes with an additional class for IVDs, spinal cord and spinal canal (See list of class here). We used nnUNet as our backbone for model training and inference.
If you use this model, please cite our work:
Warszawer Y, Molinier N, Valošek J, Shirbint E, Benveniste PL, Achiron A, Eshaghi A and Cohen-Adad J. Fully Automatic Vertebrae and Spinal Cord Segmentation Using a Hybrid Approach Combining nnU-Net and Iterative Algorithm. Proceedings of the 32th Annual Meeting of ISMRM. 2024
Open Terminal in a directory you want to work on.
Create and activate Virtual Environment (Highly recommanded):
python -m venv venv
source venv/bin/activate
Install PyTorch as described on their website.
Clone and install this repository:
git clone https://github.com/neuropoly/totalsegmentator-mri.git
python -m pip install -e totalsegmentator-mri
Install requirements:
python -m pip install -r totalsegmentator-mri/requirements.txt
A hybrid approach integrating nnU-Net with an iterative algorithm for segmenting vertebrae, IVDs, spinal cord, and spinal canal. To tackle the challenge of having many classes and class imbalance, we developed a two-step training process. A first model (model 1 - 206) was trained (single input channel: image) to identify 4 classes (IVDs, vertebrae, spinal cord and spinal canal) as well as specific IVDs (C2-C3, C7-T1 and L5-S1) representing key anatomical landmarks along the spine, so 7 classes in total (Figure 1A). The output segmentation was processed using an algorithm that distinguished odd and even IVDs based on the C2-C3, C7-T1 and L5-S1 IVD labels output by the model (Figure 1B). Then, a second nnU-Net model (model 2 - 210) was trained (two input channels: 1=image, 2=odd IVDs), to output 12 classes (Figure 1C). Finally, the output of model 2 was processed in order to assign an individual label value to each vertebrae and IVD in the final segmentation mask (Figure 1D).
Figure 1: Illustration of the hybrid method for automatic segmentation of the spine and spinal cord structures. T1w image (A) is used to train model 1, which outputs 7 classes (B). These output labels are processed to extract odd IVDs (C). The T1w and odd IVDs are used as two input channels to train model 2, which outputs 12 classes (D). These output labels are processed to extract individual IVDs and vertebrae (E).
Download the corresponding content from SPIDER dataset into 'data/raw/spider/images' and 'data/raw/spider/masks' (you can use mkdir -p data/raw/spider
to create the folder first).
Make sure git
and git-annex
are installed (You can install with sudo apt-get install git-annex -y
).
Extract data-multi-subject_PAM50_seg.zip into 'data/bids/data-multi-subject'.
Extract data-single-subject_PAM50_seg.zip into 'data/bids/data-single-subject'.
Extract whole-spine.zip (private dataset) into 'data/bids/whole-spine'.
Get the required datasets from Spine Generic Project:
source totalsegmentator-mri/run/get_spine_generic_datasets.sh
Prepares SPIDER datasets in BIDS structure:
source totalsegmentator-mri/run/prepare_spider_bids_datasets.sh
Prepares datasets in nnUNetv2 structure:
source totalsegmentator-mri/run/prepare_nnunet_datasets.sh
Train the model:
source totalsegmentator-mri/run/train_nnunet.sh
Run the model on a folder containing the images in .nii.gz format (Make sure to train the model or extract the trained nnUNet_results
into data/nnUNet/nnUNet_results
befor running):
source totalsegmentator-mri/run/inference_nnunet.sh INPUT_FOLDER OUTPUT_FOLDER
Label | Name |
---|---|
18 | vertebrae_L5 |
19 | vertebrae_L4 |
20 | vertebrae_L3 |
21 | vertebrae_L2 |
22 | vertebrae_L1 |
23 | vertebrae_T12 |
24 | vertebrae_T11 |
25 | vertebrae_T10 |
26 | vertebrae_T9 |
27 | vertebrae_T8 |
28 | vertebrae_T7 |
29 | vertebrae_T6 |
30 | vertebrae_T5 |
31 | vertebrae_T4 |
32 | vertebrae_T3 |
33 | vertebrae_T2 |
34 | vertebrae_T1 |
35 | vertebrae_C7 |
36 | vertebrae_C6 |
37 | vertebrae_C5 |
38 | vertebrae_C4 |
39 | vertebrae_C3 |
40 | vertebrae_C2 |
41 | vertebrae_C1 |
92 | sacrum |
200 | spinal_cord |
201 | spinal_canal |
202 | disc_L5_S |
203 | disc_L4_L5 |
204 | disc_L3_L4 |
205 | disc_L2_L3 |
206 | disc_L1_L2 |
207 | disc_T12_L1 |
208 | disc_T11_T12 |
209 | disc_T10_T11 |
210 | disc_T9_T10 |
211 | disc_T8_T9 |
212 | disc_T7_T8 |
213 | disc_T6_T7 |
214 | disc_T5_T6 |
215 | disc_T4_T5 |
216 | disc_T3_T4 |
217 | disc_T2_T3 |
218 | disc_T1_T2 |
219 | disc_C7_T1 |
220 | disc_C6_C7 |
221 | disc_C5_C6 |
222 | disc_C4_C5 |
223 | disc_C3_C4 |
224 | disc_C2_C3 |