Skip to content

Commit

Permalink
bugfix in load ext header with only one label
Browse files Browse the repository at this point in the history
  • Loading branch information
wasserth committed Mar 15, 2024
1 parent 940964f commit 6a7c8e8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Master
* also return statistics from python api
* add `totalseg_get_phase`
* major bugfix: rib labels were in wrong order


## Release 2.1.0
* Bugfix: add flush to DummyFile
Expand Down
1 change: 1 addition & 0 deletions tests/test_locally.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def are_logs_similar(last_log, new_log, cols, tolerance_percent=0.04):
print("Run totalsegmentator...")
reset_monitors()
for img_fn in tqdm(img_dir.glob("*.nii.gz")):
# for img_fn in tqdm(list(img_dir.glob("*.nii.gz"))[:1]):
fast = resolution == "3mm"
st = time.time()
totalsegmentator(img_fn, pred_dir / img_fn.name, fast=fast, ml=True, device=device)
Expand Down
5 changes: 5 additions & 0 deletions totalsegmentator/nifti_ext_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def load_multilabel_nifti(img_path):
ext_header = img.header.extensions[0].get_content()
ext_header = xmltodict.parse(ext_header)
ext_header = ext_header["CaretExtension"]["VolumeInformation"]["LabelTable"]["Label"]

# If only one label, ext_header is a dict instead of a list (because of xmltodict.parse()) -> convert to list
if isinstance(ext_header, dict):
ext_header = [ext_header]

label_map = {int(e["@Key"]): e["#text"] for e in ext_header}
return img, label_map

0 comments on commit 6a7c8e8

Please sign in to comment.