-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement CuImageReader and OpenSlideReader Signed-off-by: Behrooz <[email protected]> * Add unittests for CuImageReader Signed-off-by: Behrooz <[email protected]> * Add unittests for OpenSlideReader Signed-off-by: Behrooz <[email protected]> * Sort imports Signed-off-by: Behrooz <[email protected]> * Add correct boundaries Signed-off-by: Behrooz <[email protected]> * Add test cases for reading patches on a grid for CuImage Signed-off-by: Behrooz <[email protected]> * Add patch whole slide imaging dataset for pathology Signed-off-by: Behrooz <[email protected]> * Add test case for read patches for OpenSlide Signed-off-by: Behrooz <[email protected]> * flake8 and few minor changes Signed-off-by: Behrooz <[email protected]> * black Signed-off-by: Behrooz <[email protected]> * flake8 Signed-off-by: Behrooz <[email protected]> * Add kwargs to CuImageReader and OpenSlideReader's read method Signed-off-by: Behrooz <[email protected]> * Change the type hint from np.dtype to DTypeLike Signed-off-by: Behrooz <[email protected]> * Fix a bug Signed-off-by: Behrooz <[email protected]> * Implement WSIReader and unittests Signed-off-by: Behrooz <[email protected]> * Minor updates Signed-off-by: Behrooz <[email protected]> * Fix few typing issues Signed-off-by: Behrooz <[email protected]> * Revert datasets Signed-off-by: Behrooz <[email protected]> * Add shape property to openslide image object Reverse size to be compatible with output size (hxw) Signed-off-by: Behrooz <[email protected]> * Add untittest for loading the whole image Reverse the size accroding to the WSIReader Signed-off-by: Behrooz <[email protected]> * Update the whole image size Signed-off-by: Behrooz <[email protected]> * Remove optional size Signed-off-by: Behrooz <[email protected]> * Remove optional dtype Signed-off-by: Behrooz <[email protected]> * Remove _get_spatial_shape return type Signed-off-by: Behrooz <[email protected]> * Reverse the orders of dimensions of `location` to be compatible with image shape Signed-off-by: Behrooz <[email protected]> * Change test cases to use smaller image and revese location's dimensions Signed-off-by: Behrooz <[email protected]> * Replace the test TIFF and some upgrades Signed-off-by: Behrooz <[email protected]> * Update dependencies for OpenSlide Signed-off-by: Behrooz <[email protected]> * Update unittests for OpenSlide and CuImage Signed-off-by: Behrooz <[email protected]> * Fix openslide dependency Signed-off-by: Behrooz <[email protected]> * Fix doc dependencies Signed-off-by: Behrooz <[email protected]> * Minor changes Signed-off-by: Behrooz <[email protected]> * Few variable name changes Signed-off-by: Behrooz <[email protected]> * Add EnsureChannelFirst Signed-off-by: Behrooz <[email protected]> * Add metadata to WSIReader Signed-off-by: Behrooz <[email protected]>
- Loading branch information
1 parent
75b5772
commit 889c9f9
Showing
8 changed files
with
373 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import os | ||
import unittest | ||
from unittest import skipUnless | ||
from urllib import request | ||
|
||
import numpy as np | ||
from numpy.testing import assert_array_equal | ||
from parameterized import parameterized | ||
|
||
from monai.data.image_reader import WSIReader | ||
from monai.utils import optional_import | ||
|
||
_, has_cui = optional_import("cuimage") | ||
|
||
|
||
FILE_URL = "http://openslide.cs.cmu.edu/download/openslide-testdata/Generic-TIFF/CMU-1.tiff" | ||
HEIGHT = 32914 | ||
WIDTH = 46000 | ||
|
||
TEST_CASE_0 = [FILE_URL, (3, HEIGHT, WIDTH)] | ||
|
||
TEST_CASE_1 = [ | ||
FILE_URL, | ||
{"location": (HEIGHT // 2, WIDTH // 2), "size": (2, 1), "level": 0}, | ||
np.array([[[246], [246]], [[246], [246]], [[246], [246]]]), | ||
] | ||
|
||
TEST_CASE_2 = [ | ||
FILE_URL, | ||
{"location": (0, 0), "size": (2, 1), "level": 2}, | ||
np.array([[[239], [239]], [[239], [239]], [[239], [239]]]), | ||
] | ||
|
||
TEST_CASE_3 = [ | ||
FILE_URL, | ||
{ | ||
"location": (0, 0), | ||
"size": (8, 8), | ||
"level": 2, | ||
"grid_shape": (2, 1), | ||
"patch_size": 2, | ||
}, | ||
np.array( | ||
[ | ||
[[[239, 239], [239, 239]], [[239, 239], [239, 239]], [[239, 239], [239, 239]]], | ||
[[[242, 242], [242, 243]], [[242, 242], [242, 243]], [[242, 242], [242, 243]]], | ||
] | ||
), | ||
] | ||
|
||
TEST_CASE_4 = [ | ||
FILE_URL, | ||
{ | ||
"location": (0, 0), | ||
"size": (8, 8), | ||
"level": 2, | ||
"grid_shape": (2, 1), | ||
"patch_size": 1, | ||
}, | ||
np.array([[[[239]], [[239]], [[239]]], [[[243]], [[243]], [[243]]]]), | ||
] | ||
|
||
|
||
class TestCuClaraImageReader(unittest.TestCase): | ||
@parameterized.expand([TEST_CASE_0]) | ||
@skipUnless(has_cui, "Requires CuClaraImage") | ||
def test_read_whole_image(self, file_url, expected_shape): | ||
filename = self.camelyon_data_download(file_url) | ||
reader = WSIReader("CuClaraImage") | ||
img_obj = reader.read(filename) | ||
img = reader.get_data(img_obj)[0] | ||
self.assertTupleEqual(img.shape, expected_shape) | ||
|
||
@parameterized.expand([TEST_CASE_1, TEST_CASE_2]) | ||
@skipUnless(has_cui, "Requires CuClaraImage") | ||
def test_read_region(self, file_url, patch_info, expected_img): | ||
filename = self.camelyon_data_download(file_url) | ||
reader = WSIReader("CuClaraImage") | ||
img_obj = reader.read(filename) | ||
img = reader.get_data(img_obj, **patch_info)[0] | ||
self.assertTupleEqual(img.shape, expected_img.shape) | ||
self.assertIsNone(assert_array_equal(img, expected_img)) | ||
|
||
@parameterized.expand([TEST_CASE_3, TEST_CASE_4]) | ||
@skipUnless(has_cui, "Requires CuClaraImage") | ||
def test_read_patches(self, file_url, patch_info, expected_img): | ||
filename = self.camelyon_data_download(file_url) | ||
reader = WSIReader("CuClaraImage") | ||
img_obj = reader.read(filename) | ||
img = reader.get_data(img_obj, **patch_info)[0] | ||
self.assertTupleEqual(img.shape, expected_img.shape) | ||
self.assertIsNone(assert_array_equal(img, expected_img)) | ||
|
||
def camelyon_data_download(self, file_url): | ||
filename = os.path.basename(file_url) | ||
if not os.path.exists(filename): | ||
print(f"Test image [{filename}] does not exist. Downloading...") | ||
request.urlretrieve(file_url, filename) | ||
return filename | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.