Page MenuHomePhabricator

TotalSegmentator output label names conundrum
Closed, ResolvedPublic

Description

TASK FOR DISUSSION

TotalSegmentator can produce 2 kinds of output(s) segmentation files.
i. All segmentation masks in one nifti file containing all labels (--ml flag)
ii. One file each per class label with each file named accordingly.

While the (i) is being handled in T29457, this overall segmentation has no metadata of what mask/pixel is what class label. However, (ii) has the benefit of knowing the label from its file name.

Can we parse multiple nifti files to create a single segmentation LabelSetImage for preview with label names?
If Not, we can request the maintainers to output a, e.g. metadata.json file OR do it ourselves in our fork of TotalSegmentator python code.

Nevertheless,
a fork of TotalSegmentator for MITK purposes is not a bad idea in general, considering the fact that its a 3rd party maintained codebase.

Event Timeline

for "ii" the developments of T29392 could be of help (if we also implement a reader of this kind). But we would still need to generate the meta info file

So I think independent from the implementation option we choose, it would be good to know if either the classes (name, pixel value ...) are hardcoded (and where to find that table) or if there is a way to get this information at Trondheim, e.g. by a meta file @a178n proposed.

Hi Ralf,
I did some digging into the TotalSegmentator python code.
So yes, (I believe) label names/classes & their pixel values are hardcoded in the python codebase. Ref: https://github.com/wasserth/TotalSegmentator/blob/master/totalsegmentator/map_to_binary.py
I couldn't find any documentational guarantee for it. Maybe we can double check on it. But the statistics generation (--statistics flag) uses this map to calculate volume & intensity of each label. So it's a safe assumption.

Anyway, I created a personal fork of TotalSegmentator and added code to dump metadata json. It seems very easy.
Ref: https://github.com/ASHISRAVINDRAN/TotalSegmentator/blob/df3fda1886433fa577b8de646f0f907394963ddf/totalsegmentator/statistics.py#L86

I don't know who is at Trondheim (Norway) or why this info has to get there. Am I missing some info here?

for "ii" the developments of T29392 could be of help (if we also implement a reader of this kind). But we would still need to generate the meta info file

While working for implementing sub task support ( https://github.com/wasserth/TotalSegmentator/blob/master/README.md#subtasks), I see that certain subtask won't output a single nifty file with all labels. Eg. For sub task "Body", masks for body_trunc, body_extremities, skin are generated. Cannot use --ml flag. This is explicitly not allowed by the code.
Hence, either

  1. A reader for accumulating nifty files into one LabelSetImage object is needed. (and/or)
  2. Feature to add multiple nifty files into multiple new preview nodes is needed. (and/or)
  3. We modify the python code in our fork to make sure the labels are merged into one file & then we read.

How do we proceed?

PS: Slicer seems to follow approach 2.

After meeting it is decided that:

  1. Label names/classes & their pixel values that are hardcoded in the python codebase will be parsed directly and shown in MITK for 2023.04 release (Ref: https://github.com/wasserth/TotalSegmentator/blob/master/totalsegmentator/map_to_binary.py)
  2. Certain subtasks which need multiple nifti file agglomeration (eg. "Body") will not be included in the 2023.04 release.

This task may be deemed fully discussed. Hence, will be marked as resolved.
Another task, T29497, is created for tracking the full subtask support in the future.