Skip to content
Merged
Changes from all commits
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
27 changes: 10 additions & 17 deletions monai/data/wsi_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,16 @@ def get_data(
f"The image dimension should be 3 but has {patch.ndim}. "
"`WSIReader` is designed to work only with 2D images with color channel."
)

# Check if there are four color channels for RGBA
if mode == "RGBA" and patch.shape[0] != 4:
raise ValueError(
f"The image is expected to have four color channels in '{mode}' mode but has {patch.shape[0]}."
)
# Check if there are three color channels for RGB
elif mode in "RGB" and patch.shape[0] != 3:
raise ValueError(
f"The image is expected to have three color channels in '{mode}' mode but has {patch.shape[0]}. "
)
# Create a list of patches
patch_list.append(patch)

Expand Down Expand Up @@ -408,11 +417,6 @@ def get_patch(
patch = AsChannelFirst()(patch) # type: ignore

# Check if the color channel is 3 (RGB) or 4 (RGBA)
if mode == "RGBA" and patch.shape[0] != 4:
raise ValueError(
f"The image is expected to have four color channels in '{mode}' mode but has {patch.shape[0]}."
)

if mode in "RGB":
if patch.shape[0] not in [3, 4]:
raise ValueError(
Expand Down Expand Up @@ -537,15 +541,4 @@ def get_patch(
# Make it channel first
patch = AsChannelFirst()(patch) # type: ignore

# Check if the color channel is 3 (RGB) or 4 (RGBA)
if mode == "RGBA" and patch.shape[0] != 4:
raise ValueError(
f"The image is expected to have four color channels in '{mode}' mode but has {patch.shape[0]}."
)

elif mode in "RGB" and patch.shape[0] != 3:
raise ValueError(
f"The image is expected to have three color channels in '{mode}' mode but has {patch.shape[0]}. "
)

return patch