From e022915b1d3f332d1948cb125936f1655710355f Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Fri, 12 May 2023 16:06:03 +0800 Subject: [PATCH 1/3] fix #6511 Signed-off-by: KumoLiu --- monai/data/wsi_reader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/data/wsi_reader.py b/monai/data/wsi_reader.py index 2930676be3..7f1bbfefca 100644 --- a/monai/data/wsi_reader.py +++ b/monai/data/wsi_reader.py @@ -824,7 +824,7 @@ def _get_patch( f"The image is expected to have three or four color channels in '{mode}' mode but has " f"{patch.shape[self.channel_dim]}. " ) - patch = patch[:3] + patch = np.take(patch, [0, 1, 2], self.channel_dim) return patch @@ -1183,6 +1183,6 @@ def _get_patch( f"The image is expected to have three or four color channels in '{mode}' mode but has " f"{patch.shape[self.channel_dim]}. " ) - patch = patch[:3] + patch = np.take(patch, [0, 1, 2], self.channel_dim) return patch From 5dbd10014095cf765f5b1e41d0c46badb3e8f541 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Fri, 12 May 2023 16:06:17 +0800 Subject: [PATCH 2/3] update unittests Signed-off-by: KumoLiu --- tests/test_wsireader.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_wsireader.py b/tests/test_wsireader.py index 68de71d021..e86a09f78a 100644 --- a/tests/test_wsireader.py +++ b/tests/test_wsireader.py @@ -81,15 +81,15 @@ TEST_CASE_3 = [ WSI_GENERIC_TIFF_PATH, {"channel_dim": -1}, - {"location": (WSI_GENERIC_TIFF_HEIGHT // 2, WSI_GENERIC_TIFF_WIDTH // 2), "size": (2, 1), "level": 0}, - np.moveaxis(np.array([[[246], [246]], [[246], [246]], [[246], [246]]], dtype=np.uint8), 0, -1), + {"location": (WSI_GENERIC_TIFF_HEIGHT // 2, WSI_GENERIC_TIFF_WIDTH // 2), "size": (4, 1), "level": 0}, + np.moveaxis(np.array([[[246], [246], [246], [246]], [[246], [246], [246], [246]], [[246], [246], [246], [246]]], dtype=np.uint8), 0, -1), ] TEST_CASE_4 = [ WSI_GENERIC_TIFF_PATH, {"channel_dim": 2}, - {"location": (0, 0), "size": (2, 1), "level": 8}, - np.moveaxis(np.array([[[242], [242]], [[242], [242]], [[242], [242]]], dtype=np.uint8), 0, -1), + {"location": (0, 0), "size": (4, 1), "level": 8}, + np.moveaxis(np.array([[[242], [242], [242], [242]], [[242], [242], [242], [242]], [[242], [242], [242], [242]]], dtype=np.uint8), 0, -1), ] TEST_CASE_5 = [ From 8c0b6be969abb6a3af40e5da4301e07d8268c5ec Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Fri, 12 May 2023 16:15:12 +0800 Subject: [PATCH 3/3] fix flake8 Signed-off-by: KumoLiu --- tests/test_wsireader.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_wsireader.py b/tests/test_wsireader.py index e86a09f78a..aae2b0dbaf 100644 --- a/tests/test_wsireader.py +++ b/tests/test_wsireader.py @@ -82,14 +82,26 @@ WSI_GENERIC_TIFF_PATH, {"channel_dim": -1}, {"location": (WSI_GENERIC_TIFF_HEIGHT // 2, WSI_GENERIC_TIFF_WIDTH // 2), "size": (4, 1), "level": 0}, - np.moveaxis(np.array([[[246], [246], [246], [246]], [[246], [246], [246], [246]], [[246], [246], [246], [246]]], dtype=np.uint8), 0, -1), + np.moveaxis( + np.array( + [[[246], [246], [246], [246]], [[246], [246], [246], [246]], [[246], [246], [246], [246]]], dtype=np.uint8 + ), + 0, + -1, + ), ] TEST_CASE_4 = [ WSI_GENERIC_TIFF_PATH, {"channel_dim": 2}, {"location": (0, 0), "size": (4, 1), "level": 8}, - np.moveaxis(np.array([[[242], [242], [242], [242]], [[242], [242], [242], [242]], [[242], [242], [242], [242]]], dtype=np.uint8), 0, -1), + np.moveaxis( + np.array( + [[[242], [242], [242], [242]], [[242], [242], [242], [242]], [[242], [242], [242], [242]]], dtype=np.uint8 + ), + 0, + -1, + ), ] TEST_CASE_5 = [