Skip to content

Commit

Permalink
Update image_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
NataliaAlves13 committed Apr 23, 2024
1 parent b7ffe03 commit 4b402c9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/picai_eval/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +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:
try:
return np.load(path)['softmax'].astype('float32')[1] # nnUnet format
except Exception as e:
return np.load(path)['probabilities'].astype('float32')[1] # nnUnet format
# read the nnU-Net format
data = np.load(path)
data = data["softmax"] if "softmax" in data else data["probabilities"]
return data.astype("float32")[1]
else:
raise ValueError(f"Unexpected file path. Supported file formats: .nii(.gz), .mha, .npy and .npz. Got: {path}.")

Expand All @@ -88,5 +88,4 @@ 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

0 comments on commit 4b402c9

Please sign in to comment.