Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSI reader #1548

Merged
merged 53 commits into from
Mar 5, 2021
Merged

WSI reader #1548

merged 53 commits into from
Mar 5, 2021

Conversation

bhashemian
Copy link
Member

@bhashemian bhashemian commented Feb 4, 2021

Fixes #1504

Description

Training models for pathology use cases requires loading patches from Whole Slide Imaging (WSI) scans. These images are enormous in size and usually much larger than user's available RAM (#1504). This PR provide a solution by implementing whole slide image readers for CuImage and OpenSlide.

Types of changes

  • 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 --codeformat --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@bhashemian bhashemian reopened this Feb 4, 2021
@bhashemian bhashemian requested a review from Nic-Ma February 8, 2021 05:19
@bhashemian
Copy link
Member Author

@wyli, @Nic-Ma
The mypy complains are for the existing code and I think they are due to the third-party libraries update. For instance, the first one is about np.eye, which I suspect it is because of the interface file ( __init__.pyi) that has been added after numpy==1.20 where the return type of np.eye is defined as Any. Have you encounter this in any other place in MONAI?

monai/data/image_reader.py:252:9: error: Returning Any from function declared to return "ndarray"  [no-any-return]
286
monai/data/image_reader.py:280:13: error: Returning Any from function declared to return "ndarray"  [no-any-return]
287
monai/data/image_reader.py:393:9: error: Returning Any from function declared to return "ndarray"  [no-any-return]

@bhashemian bhashemian marked this pull request as ready for review February 8, 2021 05:48
@bhashemian bhashemian requested a review from wyli February 11, 2021 17:55
@bhashemian
Copy link
Member Author

@wyli, @Nic-Ma
The mypy complains are for the existing code and I think they are due to the third-party libraries update. For instance, the first one is about np.eye, which I suspect it is because of the interface file ( __init__.pyi) that has been added after numpy==1.20 where the return type of np.eye is defined as Any. Have you encounter this in any other place in MONAI?

monai/data/image_reader.py:252:9: error: Returning Any from function declared to return "ndarray"  [no-any-return]
286
monai/data/image_reader.py:280:13: error: Returning Any from function declared to return "ndarray"  [no-any-return]
287
monai/data/image_reader.py:393:9: error: Returning Any from function declared to return "ndarray"  [no-any-return]

@wyli @Nic-Ma, what do you suggest here?

Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, please see some initial comments inline, I'll try it out with an EA container soon...

monai/data/image_reader.py Show resolved Hide resolved
tests/test_openslide_reader.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Nic-Ma Nic-Ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick update.
I put several minor comments inline, others look good to me.
And please add this new object to the "init.py" of mode/data/ and docs/sources/data.

Thanks.

monai/data/image_reader.py Outdated Show resolved Hide resolved
for name in filenames:
img = self.wsi_reader(name)
if self.wsi_reader_name == "openslide":
img.shape = (img.dimensions[1], img.dimensions[0], 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it support images with channel = 1 or no channel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only supports RGB data as the output and it explicitly convert it to RGB, so the channels always should be 3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, the doc suggests RGBA (https://openslide.org/api/python/#openslide.OpenSlide.associated_images), I think we should make it clear in the docstring if we only support RGB

monai/data/image_reader.py Outdated Show resolved Hide resolved
monai/data/image_reader.py Outdated Show resolved Hide resolved
monai/data/image_reader.py Outdated Show resolved Hide resolved
monai/data/image_reader.py Show resolved Hide resolved
monai/data/image_reader.py Show resolved Hide resolved
self,
img_obj,
location: Tuple[int, int] = (0, 0),
size: Optional[Tuple[int, int]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to use spatial_size, otherwise, it may be confusing whether it contains channel dim.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of agree here but since both OpenSlide and cuClaraImage use size to define this input argument, I found using another name confusing for people who has ML in pathology background and has worked with WSI in the past.

@bhashemian bhashemian enabled auto-merge (squash) March 4, 2021 18:01
@bhashemian bhashemian requested a review from Nic-Ma March 5, 2021 00:01
Copy link
Contributor

@Nic-Ma Nic-Ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
Thanks for your quick update!

@bhashemian bhashemian merged commit 889c9f9 into Project-MONAI:master Mar 5, 2021
@bhashemian bhashemian deleted the pathology_dataset branch March 5, 2021 15:20
@KumoLiu KumoLiu mentioned this pull request Dec 28, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WSI image reader
4 participants