Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change image_utils.py to work with nnunetv2 predictions and ground truth labels with multi-class segmentations. #17

Merged
merged 8 commits into from
May 6, 2024
6 changes: 5 additions & 1 deletion src/picai_eval/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def read_image(path: PathLike):
elif '.nii' in path or '.mha' in path or 'mhd' in path:
return sitk.GetArrayFromImage(sitk.ReadImage(path))
elif '.npz' in path:
return np.load(path)['softmax'].astype('float32')[1] # nnUnet format
try:
return np.load(path)['softmax'].astype('float32')[1] # nnUnet format
except:
return np.load(path)['probabilities'].astype('float32')[1] # nnUnet format
else:
raise ValueError(f"Unexpected file path. Supported file formats: .nii(.gz), .mha, .npy and .npz. Got: {path}.")

Expand All @@ -85,4 +88,5 @@ def read_label(path: PathLike) -> "npt.NDArray[np.int32]":
"""Read label, given a filepath"""
# read label and ensure correct dtype
lbl: "npt.NDArray[np.int32]" = np.array(read_image(path), dtype=np.int32)
lbl[lbl!=1]=0
return lbl
Loading