Home

Awesome

TotalSegmentator

Tool for segmentation of most major anatomical structures in any CT or MR image. It was trained on a wide range of different CT and MR images (different scanners, institutions, protocols,...) and therefore should work well on most images. A large part of the training dataset can be downloaded here: CT dataset (1228 subjects) and MR dataset (298 subjects). You can also try the tool online at totalsegmentator.com or as 3D Slicer extension.

ANNOUNCEMENT: We recently added support for MR images. Try out by using the task -ta total_mr or see more details in our paper.

Main classes for CT: Alt text

Main classes for MR: Alt text

See here for all available structures.

Created by the department of Research and Analysis at University Hospital Basel. If you use it please cite our Radiology AI paper (free preprint). If you use it for MR images please cite the TotalSegmentator MRI paper. Please also cite nnUNet since TotalSegmentator is heavily based on it.

Installation

TotalSegmentator works on Ubuntu, Mac, and Windows and on CPU and GPU.

Install dependencies:

Optionally:

Install Totalsegmentator

pip install TotalSegmentator

Usage

For CT images:

TotalSegmentator -i ct.nii.gz -o segmentations

For MR images:

TotalSegmentator -i mri.nii.gz -o segmentations --task total_mr

Note: A Nifti file or a folder (or zip file) with all DICOM slices of one patient is allowed as input.

Note: If you run on CPU use the option --fast or --roi_subset to greatly improve runtime.

Note: This is not a medical device and is not intended for clinical usage.

Subtasks

Alt text

Next to the default task (total) there are more subtasks with more classes. If the taskname ends with _mr it works for MR images, otherwise for CT images.

Openly available for any usage:

*: These models are not trained on the full totalsegmentator dataset but on some small other datasets. Therefore, expect them to work less robustly.

Available with a license (free licenses available for non-commercial usage here. For a commercial license contact jakob.wasserthal@usb.ch):

Usage:

TotalSegmentator -i ct.nii.gz -o segmentations -ta <task_name>

Confused by all the structures and tasks? Check this to search through available structures and tasks.

The mapping from label ID to class name can be found here.

Advanced settings

Run via docker

We also provide a docker container which can be used the following way

docker run --gpus 'device=0' --ipc=host -v /absolute/path/to/my/data/directory:/tmp wasserth/totalsegmentator:2.2.1 TotalSegmentator -i /tmp/ct.nii.gz -o /tmp/segmentations

Running v1

If you want to keep on using TotalSegmentator v1 (e.g. because you do not want to change your pipeline) you can install it with the following command:

pip install TotalSegmentator==1.5.7

The documentation for v1 can be found here. Bugfixes for v1 are developed in the branch v1_bugfixes. Our Radiology AI publication refers to TotalSegmentator v1.

Resource Requirements

Totalsegmentator has the following runtime and memory requirements (using an Nvidia RTX 3090 GPU): (1.5mm is the normal model and 3mm is the --fast model. With v2 the runtimes have increased a bit since we added more classes.)

Alt text

If you want to reduce memory consumption you can use the following options:

Python API

You can run totalsegmentator via Python:

import nibabel as nib
from totalsegmentator.python_api import totalsegmentator

if __name__ == "__main__":
    # option 1: provide input and output as file paths
    totalsegmentator(input_path, output_path)
    
    # option 2: provide input and output as nifti image objects
    input_img = nib.load(input_path)
    output_img = totalsegmentator(input_img)
    nib.save(output_img, output_path)

You can see all available arguments here. Running from within the main environment should avoid some multiprocessing issues.

The segmentation image contains the names of the classes in the extended header. If you want to load this additional header information you can use the following code (requires pip install xmltodict):

from totalsegmentator.nifti_ext_header import load_multilabel_nifti

segmentation_nifti_img, label_map_dict = load_multilabel_nifti(image_path)

Install latest master branch (contains latest bug fixes)

pip install git+https://github.com/wasserth/TotalSegmentator.git

Other commands

If you want to know which contrast phase a CT image is you can use the following command (requires pip install xgboost). More details can be found here:

totalseg_get_phase -i ct.nii.gz -o contrast_phase.json

If you want to combine some subclasses (e.g. lung lobes) into one binary mask (e.g. entire lung) you can use the following command:

totalseg_combine_masks -i totalsegmentator_output_dir -o combined_mask.nii.gz -m lungcomm 

Normally weights are automatically downloaded when running TotalSegmentator. If you want to download the weights with an extra command (e.g. when building a docker container) use this:

totalseg_download_weights -t <task_name>

This will download them to ~/.totalsegmentator/nnunet/results. You can change this path by doing export TOTALSEG_HOME_DIR=/new/path/.totalsegmentator. If your machine has no internet, then download on another machine with internet and copy ~/.totalsegmentator to the machine without internet.

After acquiring a license number for the non-open tasks you can set it with the following command:

totalseg_set_license -l aca_12345678910

Train/validation/test split

The exact split of the dataset can be found in the file meta.csv inside of the dataset. This was used for the validation in our paper. The exact numbers of the results for the high-resolution model (1.5mm) can be found here. The paper shows these numbers in the supplementary materials Figure 11.

Retrain model and run evaluation

See here for more info on how to train a nnU-Net yourself on the TotalSegmentator dataset, how to split the data into train/validation/test set as in our paper, and how to run the same evaluation as in our paper.

Typical problems

ITK loading Error When you get the following error message

ITK ERROR: ITK only supports orthonormal direction cosines. No orthonormal definition was found!

you should do

pip install SimpleITK==2.0.2

Alternatively you can try

fslorient -copysform2qform input_file
fslreorient2std input_file output_file

Bad segmentations When you get bad segmentation results check the following:

Other

Reference

For more details see our Radiology AI paper (freely available preprint). If you use this tool please cite it as follows

Wasserthal, J., Breit, H.-C., Meyer, M.T., Pradella, M., Hinck, D., Sauter, A.W., Heye, T., Boll, D., Cyriac, J., Yang, S., Bach, M., Segeroth, M., 2023. TotalSegmentator: Robust Segmentation of 104 Anatomic Structures in CT Images. Radiology: Artificial Intelligence. https://doi.org/10.1148/ryai.230024

Please also cite nnUNet since TotalSegmentator is heavily based on it. Moreover, we would really appreciate it if you let us know what you are using this tool for. You can also tell us what classes we should add in future releases. You can do so here.

Class details

The following table shows a list of all classes for task total.

TA2 is a standardized way to name anatomy. Mostly the TotalSegmentator names follow this standard. For some classes they differ which you can see in the table below.

Here you can find a mapping of the TotalSegmentator classes to SNOMED-CT codes.

IndexTotalSegmentator nameTA2 name
1spleen
2kidney_right
3kidney_left
4gallbladder
5liver
6stomach
7pancreas
8adrenal_gland_rightsuprarenal gland
9adrenal_gland_leftsuprarenal gland
10lung_upper_lobe_leftsuperior lobe of left lung
11lung_lower_lobe_leftinferior lobe of left lung
12lung_upper_lobe_rightsuperior lobe of right lung
13lung_middle_lobe_rightmiddle lobe of right lung
14lung_lower_lobe_rightinferior lobe of right lung
15esophagus
16trachea
17thyroid_gland
18small_bowelsmall intestine
19duodenum
20colon
21urinary_bladder
22prostate
23kidney_cyst_left
24kidney_cyst_right
25sacrum
26vertebrae_S1
27vertebrae_L5
28vertebrae_L4
29vertebrae_L3
30vertebrae_L2
31vertebrae_L1
32vertebrae_T12
33vertebrae_T11
34vertebrae_T10
35vertebrae_T9
36vertebrae_T8
37vertebrae_T7
38vertebrae_T6
39vertebrae_T5
40vertebrae_T4
41vertebrae_T3
42vertebrae_T2
43vertebrae_T1
44vertebrae_C7
45vertebrae_C6
46vertebrae_C5
47vertebrae_C4
48vertebrae_C3
49vertebrae_C2
50vertebrae_C1
51heart
52aorta
53pulmonary_vein
54brachiocephalic_trunk
55subclavian_artery_right
56subclavian_artery_left
57common_carotid_artery_right
58common_carotid_artery_left
59brachiocephalic_vein_left
60brachiocephalic_vein_right
61atrial_appendage_left
62superior_vena_cava
63inferior_vena_cava
64portal_vein_and_splenic_veinhepatic portal vein
65iliac_artery_leftcommon iliac artery
66iliac_artery_rightcommon iliac artery
67iliac_vena_leftcommon iliac vein
68iliac_vena_rightcommon iliac vein
69humerus_left
70humerus_right
71scapula_left
72scapula_right
73clavicula_leftclavicle
74clavicula_rightclavicle
75femur_left
76femur_right
77hip_left
78hip_right
79spinal_cord
80gluteus_maximus_leftgluteus maximus muscle
81gluteus_maximus_rightgluteus maximus muscle
82gluteus_medius_leftgluteus medius muscle
83gluteus_medius_rightgluteus medius muscle
84gluteus_minimus_leftgluteus minimus muscle
85gluteus_minimus_rightgluteus minimus muscle
86autochthon_left
87autochthon_right
88iliopsoas_leftiliopsoas muscle
89iliopsoas_rightiliopsoas muscle
90brain
91skull
92rib_left_1
93rib_left_2
94rib_left_3
95rib_left_4
96rib_left_5
97rib_left_6
98rib_left_7
99rib_left_8
100rib_left_9
101rib_left_10
102rib_left_11
103rib_left_12
104rib_right_1
105rib_right_2
106rib_right_3
107rib_right_4
108rib_right_5
109rib_right_6
110rib_right_7
111rib_right_8
112rib_right_9
113rib_right_10
114rib_right_11
115rib_right_12
116sternum
117costal_cartilages

Class map for task total_mr:

IndexTotalSegmentator nameTA2 name
1spleen
2kidney_right
3kidney_left
4gallbladder
5liver
6stomach
7pancreas
8adrenal_gland_rightsuprarenal gland
9adrenal_gland_leftsuprarenal gland
10lung_left
11lung_right
12esophagus
13small_bowelsmall intestine
14duodenum
15colon
16urinary_bladder
17prostate
18sacrum
19vertebrae
20intervertebral_discs
21spinal_cord
22heart
23aorta
24inferior_vena_cava
25portal_vein_and_splenic_veinhepatic portal vein
26iliac_artery_leftcommon iliac artery
27iliac_artery_rightcommon iliac artery
28iliac_vena_leftcommon iliac vein
29iliac_vena_rightcommon iliac vein
30humerus_left
31humerus_right
32fibula
33tibia
34femur_left
35femur_right
36hip_left
37hip_right
38gluteus_maximus_leftgluteus maximus muscle
39gluteus_maximus_rightgluteus maximus muscle
40gluteus_medius_leftgluteus medius muscle
41gluteus_medius_rightgluteus medius muscle
42gluteus_minimus_leftgluteus minimus muscle
43gluteus_minimus_rightgluteus minimus muscle
44autochthon_left
45autochthon_right
46iliopsoas_leftiliopsoas muscle
47iliopsoas_rightiliopsoas muscle
48quadriceps_femoris_left
49quadriceps_femoris_right
50thigh_medial_compartment_left
51thigh_medial_compartment_right
52thigh_posterior_compartment_left
53thigh_posterior_compartment_right
54sartorius_left
55sartorius_right
56brain