Skip to content

Commit d421efc

Browse files
authored
Fix channel_dim bug in TiffFileWSIReader and CuCIMWSIReader (#6514)
Fixes #6511 . ### Description ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: KumoLiu <yunl@nvidia.com>
1 parent 7f3d3fc commit d421efc

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

monai/data/wsi_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ def _get_patch(
824824
f"The image is expected to have three or four color channels in '{mode}' mode but has "
825825
f"{patch.shape[self.channel_dim]}. "
826826
)
827-
patch = patch[:3]
827+
patch = np.take(patch, [0, 1, 2], self.channel_dim)
828828

829829
return patch
830830

@@ -1183,6 +1183,6 @@ def _get_patch(
11831183
f"The image is expected to have three or four color channels in '{mode}' mode but has "
11841184
f"{patch.shape[self.channel_dim]}. "
11851185
)
1186-
patch = patch[:3]
1186+
patch = np.take(patch, [0, 1, 2], self.channel_dim)
11871187

11881188
return patch

tests/test_wsireader.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,27 @@
8181
TEST_CASE_3 = [
8282
WSI_GENERIC_TIFF_PATH,
8383
{"channel_dim": -1},
84-
{"location": (WSI_GENERIC_TIFF_HEIGHT // 2, WSI_GENERIC_TIFF_WIDTH // 2), "size": (2, 1), "level": 0},
85-
np.moveaxis(np.array([[[246], [246]], [[246], [246]], [[246], [246]]], dtype=np.uint8), 0, -1),
84+
{"location": (WSI_GENERIC_TIFF_HEIGHT // 2, WSI_GENERIC_TIFF_WIDTH // 2), "size": (4, 1), "level": 0},
85+
np.moveaxis(
86+
np.array(
87+
[[[246], [246], [246], [246]], [[246], [246], [246], [246]], [[246], [246], [246], [246]]], dtype=np.uint8
88+
),
89+
0,
90+
-1,
91+
),
8692
]
8793

8894
TEST_CASE_4 = [
8995
WSI_GENERIC_TIFF_PATH,
9096
{"channel_dim": 2},
91-
{"location": (0, 0), "size": (2, 1), "level": 8},
92-
np.moveaxis(np.array([[[242], [242]], [[242], [242]], [[242], [242]]], dtype=np.uint8), 0, -1),
97+
{"location": (0, 0), "size": (4, 1), "level": 8},
98+
np.moveaxis(
99+
np.array(
100+
[[[242], [242], [242], [242]], [[242], [242], [242], [242]], [[242], [242], [242], [242]]], dtype=np.uint8
101+
),
102+
0,
103+
-1,
104+
),
93105
]
94106

95107
TEST_CASE_5 = [

0 commit comments

Comments
 (0)