Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yiheng Wang <[email protected]>
  • Loading branch information
yiheng-wang-nv committed Dec 16, 2024
1 parent 83a1daf commit acf2cba
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,24 @@
from monai.utils import MetaKeys, SpaceKeys, TraceKeys, ensure_tuple, optional_import, require_pkg

if TYPE_CHECKING:
import cupy as cp
import itk
import kvikio
import nibabel as nib
import nrrd
import pydicom
from nibabel.nifti1 import Nifti1Image
from PIL import Image as PILImage

has_nrrd = has_itk = has_nib = has_pil = has_pydicom = has_cp = has_kvikio = True
has_nrrd = has_itk = has_nib = has_pil = has_pydicom = True
else:
itk, has_itk = optional_import("itk", allow_namespace_pkg=True)
nib, has_nib = optional_import("nibabel")
Nifti1Image, _ = optional_import("nibabel.nifti1", name="Nifti1Image")
PILImage, has_pil = optional_import("PIL.Image")
pydicom, has_pydicom = optional_import("pydicom")
nrrd, has_nrrd = optional_import("nrrd", allow_namespace_pkg=True)
cp, has_cp = optional_import("cupy")
kvikio, has_kvikio = optional_import("kvikio")

cp, has_cp = optional_import("cupy")
kvikio, has_kvikio = optional_import("kvikio")

__all__ = ["ImageReader", "ITKReader", "NibabelReader", "NumpyReader", "PILReader", "PydicomReader", "NrrdReader"]

Expand Down Expand Up @@ -905,7 +904,9 @@ def __init__(
self.as_closest_canonical = as_closest_canonical
self.squeeze_non_spatial_dims = squeeze_non_spatial_dims
if to_gpu and (not has_cp or not has_kvikio):
warnings.warn("NibabelReader: CuPy and/or Kvikio not installed for GPU loading, falling back to CPU loading.")
warnings.warn(
"NibabelReader: CuPy and/or Kvikio not installed for GPU loading, falling back to CPU loading."
)
to_gpu = False

self.to_gpu = to_gpu
Expand Down Expand Up @@ -948,7 +949,7 @@ def read(self, data: Sequence[PathLike] | PathLike, **kwargs):
img_.append(img) # type: ignore
return img_ if len(filenames) > 1 else img_[0]

def get_data(self, img) -> tuple[np.ndarray | cp.ndarray, dict]:
def get_data(self, img) -> tuple[np.ndarray, dict]:
"""
Extract data array and metadata from loaded image and return them.
This function returns two objects, first is numpy array of image data, second is dict of metadata.
Expand All @@ -960,7 +961,7 @@ def get_data(self, img) -> tuple[np.ndarray | cp.ndarray, dict]:
img: a Nibabel image object loaded from an image file or a list of Nibabel image objects.
"""
img_array: list[np.ndarray | cp.ndarray] = []
img_array: list[np.ndarray] = []
compatible_meta: dict = {}

for i, filename in zip(ensure_tuple(img), self.filenames):
Expand Down

0 comments on commit acf2cba

Please sign in to comment.