Skip to content

Bug for changing channel_dim in Whole slide image reader #6511

@Dylan-H-Wang

Description

@Dylan-H-Wang

I tried to change the default value for channel_dim in CuCIMWSIReader and found that the outputs were not correct. Therefore, I checked the source code and identified the buggy part:

if mode in "RGB":
if patch.shape[self.channel_dim] not in [3, 4]:
raise ValueError(
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]

Suppose I set channel_dim=-1, and then patch = patch[:3] is not modifying the channel part at all, instead, it changes the image dimension!

Same problem for TiffFileWSIReader:

MONAI/monai/data/wsi_reader.py

Lines 1179 to 1186 in e5cf74a

# Check if the color channel is 3 (RGB) or 4 (RGBA)
if mode in "RGB":
if patch.shape[self.channel_dim] not in [3, 4]:
raise ValueError(
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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions