Skip to content

Commit

Permalink
Adjust code for corner case with kidney instance ids
Browse files Browse the repository at this point in the history
  • Loading branch information
anwai98 committed Jan 9, 2025
1 parent 137f6d0 commit 956ce39
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions torch_em/data/datasets/medical/kits.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,22 @@ def _preprocess_inputs(path):
f.create_dataset("labels/all", data=labels, compression="gzip")

# Add annotations for kidneys per rater.
assert kidney_anns, "There must be kidney annotations."
_k_exclusive = False
if not kidney_anns:
_k_exclusive = True
kidney_anns = natsorted(glob(os.path.join(patient_dir, "instances", "kidney_instance-2*")))

assert kidney_anns, f"There must be kidney annotations for '{patient_id}'."
for p in kidney_anns:
masks = np.zeros_like(raw)
rater_id = p[-8] # The rater count

# Get the other kidney instance.
other_p = p.replace("instance-1", "instance-2")
if _k_exclusive:
print("The kidney annotations are numbered strangely.")
other_p = p.replace("instance-2", "instance-3")
else:
other_p = p.replace("instance-1", "instance-2")

# Merge both left and right kidney as one semantic id.
masks[nib.load(p).get_fdata() > 0] = 1
Expand All @@ -118,7 +127,7 @@ def _preprocess_inputs(path):
f.create_dataset(f"labels/kidney/rater_{rater_id}", data=masks, compression="gzip")

# Add annotations for tumor per rater.
assert tumor_anns, "There must be tumor annotations."
assert tumor_anns, f"There must be tumor annotations for '{patient_id}'."
# Find the raters.
raters = [p[-8] for p in tumor_anns]
# Get masks per rater
Expand Down

0 comments on commit 956ce39

Please sign in to comment.