Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,10 @@ def __init__(self, reader_lib: str = "OpenSlide"):
if has_osl:
self.wsi_reader = openslide.OpenSlide
elif self.reader_lib == "cucim":
if has_cim:
if has_cim and hasattr(cucim, "CuImage"):
self.wsi_reader = cucim.CuImage
else:
raise ImportError("Please check the cuCIM installation.")
else:
raise ValueError('`reader_lib` should be either "cuCIM" or "OpenSlide"')

Expand Down
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ Sphinx==3.5.3
recommonmark==0.6.0
sphinx-autodoc-typehints==1.11.1
sphinx-rtd-theme==0.5.2
cucim~=0.19.0; platform_system == "Linux"
cucim>=21.8.2; platform_system == "Linux"
openslide-python==1.1.2
imagecodecs; platform_system == "Linux"
tifffile; platform_system == "Linux"
pandas
requests
einops
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ all =
tqdm>=4.47.0
lmdb
psutil
cucim~=0.19.0
cucim>=21.8.2
openslide-python==1.1.2
pandas
einops
Expand Down Expand Up @@ -68,7 +68,7 @@ lmdb =
psutil =
psutil
cucim =
cucim~=0.19.0
cucim>=21.8.2
openslide =
openslide-python==1.1.2
pandas =
Expand Down
6 changes: 4 additions & 2 deletions tests/test_cuimage_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from monai.data.image_reader import WSIReader
from monai.utils import optional_import

_, has_cim = optional_import("cucim")
cucim, has_cucim = optional_import("cucim")
has_cucim = has_cucim and hasattr(cucim, "CuImage")
PILImage, has_pil = optional_import("PIL.Image")

FILE_URL = "http://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/CMU-1.tiff"
Expand Down Expand Up @@ -83,7 +84,7 @@


class TestCuCIMReader(unittest.TestCase):
@skipUnless(has_cim, "Requires CuCIM")
@skipUnless(has_cucim, "Requires CuCIM")
def setUp(self):
download_url(FILE_URL, FILE_PATH, "5a3cfd4fd725c50578ddb80b517b759f")

Expand Down Expand Up @@ -112,6 +113,7 @@ def test_read_patches(self, file_path, patch_info, expected_img):

@parameterized.expand([TEST_CASE_RGB_0, TEST_CASE_RGB_1])
@skipUnless(has_pil, "Requires PIL")
@skipUnless(has_cucim and cucim.__version__ == "0.19.0", "Skipped for cicum>0.19.0")
def test_read_rgba(self, img_expected):
image = {}
reader = WSIReader("cuCIM")
Expand Down
11 changes: 6 additions & 5 deletions tests/test_lesion_froc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
from monai.apps.pathology.metrics import LesionFROC
from monai.utils import optional_import

_, has_cucim = optional_import("cucim")
_cucim, has_cucim = optional_import("cucim")
has_cucim = has_cucim and hasattr(_cucim, "CuImage")
_, has_skimage = optional_import("skimage.measure")
_, has_sp = optional_import("scipy.ndimage")
PILImage, has_pil = optional_import("PIL.Image")
imwrite, has_tif = optional_import("tifffile", name="imwrite")


def save_as_tif(filename, array):
array = array[::-1, ...] # Upside-down
img = PILImage.fromarray(array)
if not filename.endswith(".tif"):
filename += ".tif"
img.save(os.path.join("tests", "testing_data", filename))
file_path = os.path.join("tests", "testing_data", filename)
imwrite(file_path, array, compress="jpeg", tile=(16, 16))


def around(val, interval=3):
Expand Down Expand Up @@ -301,7 +302,7 @@ class TestEvaluateTumorFROC(unittest.TestCase):
@skipUnless(has_cucim, "Requires cucim")
@skipUnless(has_skimage, "Requires skimage")
@skipUnless(has_sp, "Requires scipy")
@skipUnless(has_pil, "Requires PIL")
@skipUnless(has_tif, "Requires tifffile")
def setUp(self):
prepare_test_data()

Expand Down
3 changes: 2 additions & 1 deletion tests/test_patch_wsi_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from monai.apps.utils import download_url
from monai.utils import optional_import

_, has_cim = optional_import("cucim")
_cucim, has_cim = optional_import("cucim")
has_cim = has_cim and hasattr(_cucim, "CuImage")
_, has_osl = optional_import("openslide")

FILE_URL = "http://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/CMU-1.tiff"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_smartcache_patch_wsi_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from monai.apps.utils import download_url
from monai.utils import optional_import

_, has_cim = optional_import("cucim")
_cucim, has_cim = optional_import("cucim")
has_cim = has_cim and hasattr(_cucim, "CuImage")

FILE_URL = "http://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/CMU-1.tiff"
FILE_PATH = os.path.join(os.path.dirname(__file__), "testing_data", "temp_" + os.path.basename(FILE_URL))
Expand Down