wasserth / TotalSegmentator

Tool for robust segmentation of >100 important anatomical structures in CT and MR images
Apache License 2.0
1.51k stars 252 forks source link

Bad output for lung segmentation? #241

Closed mattragoza closed 11 months ago

mattragoza commented 11 months ago

Hello, thank you for providing this tool and making it easy to use. I am trying to use TS for lung segmentation in CT images. I would like masks of the lung lobes, vessels, airways, and combined lung masks.

I am applying the segmentation to a public 4DCT lung dataset from this link: https://med.emory.edu/departments/radiation-oncology/research-laboratories/deformable-image-registration/downloads-and-reference-data/4dct.html

Here is my basic script for running the segmentation (after converting the images to NIFTI format):

data_name=Emory-4DCT
case_id=1
phase=50

data_root=data/$data_name

case_name=Case${case_id}Pack
case_dir=$data_root/$case_name

image_dir=$case_dir/NIFTI
mask_dir=$case_dir/TotalSegment

image_name=case${case_id}_T${phase}
image_file=$image_dir/$image_name.nii.gz
output_dir=$mask_dir/$image_name

TotalSegmentator -i $image_file -o $output_dir --device gpu --statistics --preview -ta total --roi_subset lung_upper_lobe_right lung_upper_lobe_left lung_middle_lobe_right lung_lower_lobe_right lung_lower_lobe_left
TotalSegmentator -i $image_file -o $output_dir --device gpu --statistics --preview -ta lung_vessels
totalseg_combine_masks -i $output_dir -o $output_dir/lung_combined_mask.nii.gz -m lung

echo Done

The preview.png image for the vessel segmentation is ok, but the regular lung segmentation appears to be mostly zero. In fact when I take a sum of the combined lung mask it has only 20 nonzero voxels. Here are the preview.png images:

preview_lung_vessels preview_total statistics.json

What am I doing wrong?

wasserth commented 11 months ago

The CT image does not have the original intensity values anymore, but they were normalized/changed. Use the CT image with the original HU values (e.g. air das intensity of roughly -900).

mattragoza commented 11 months ago

Could you provide descriptive statistics for the training data, i.e. mean and variance or median and IQR? I don't have access to unnormalized versions of this particular data set, this is how the data were provided. An estimate would be fine, I just don't want to modify my data in an unprincipled way

mattragoza commented 11 months ago

I was able to determine that the images were normalized by subtracting 1000, adding it back seemed to fix the segmentation masks.