MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / CuCIMWSIReader

Class CuCIMWSIReader

monai/data/wsi_reader.py:741–1020  ·  view source on GitHub ↗

Read whole slide images and extract patches using cuCIM library. Args: level: the whole slide image level at which the patches are extracted. mpp: the resolution in micron per pixel at which the patches are extracted. mpp_rtol: the acceptable relative tolerance for

Source from the content-addressed store, hash-verified

739
740@require_pkg(pkg_name="cucim")
741class CuCIMWSIReader(BaseWSIReader):
742 """
743 Read whole slide images and extract patches using cuCIM library.
744
745 Args:
746 level: the whole slide image level at which the patches are extracted.
747 mpp: the resolution in micron per pixel at which the patches are extracted.
748 mpp_rtol: the acceptable relative tolerance for resolution in micro per pixel.
749 mpp_atol: the acceptable absolute tolerance for resolution in micro per pixel.
750 power: the objective power at which the patches are extracted.
751 power_rtol: the acceptable relative tolerance for objective power.
752 power_atol: the acceptable absolute tolerance for objective power.
753 channel_dim: the desired dimension for color channel. Default to 0 (channel first).
754 dtype: the data type of output image. Defaults to `np.uint8`.
755 device: target device to put the extracted patch. Note that if device is "cuda"",
756 the output will be converted to torch tenor and sent to the gpu even if the dtype is numpy.
757 mode: the output image color mode, "RGB" or "RGBA". Defaults to "RGB".
758 num_workers: number of workers for multi-thread image loading.
759 kwargs: additional args for `cucim.CuImage` module:
760 https://github.com/rapidsai/cucim/blob/main/cpp/include/cucim/cuimage.h
761
762 Notes:
763 Only one of resolution parameters, `level`, `mpp`, or `power`, should be provided.
764 If such parameters are provided in `get_data` method, those will override the values provided here.
765 If none of them are provided here or in `get_data`, `level=0` will be used.
766
767 """
768
769 supported_suffixes = ["tif", "tiff", "svs"]
770 backend = "cucim"
771
772 def __init__(self, num_workers: int = 0, **kwargs):
773 super().__init__(**kwargs)
774 self.num_workers = num_workers
775
776 @staticmethod
777 def get_level_count(wsi) -> int:
778 """
779 Returns the number of levels in the whole slide image.
780
781 Args:
782 wsi: a whole slide image object loaded from a file.
783
784 """
785 return wsi.resolutions["level_count"] # type: ignore
786
787 def get_size(self, wsi, level: int) -> tuple[int, int]:
788 """
789 Returns the size (height, width) of the whole slide image at a given level.
790
791 Args:
792 wsi: a whole slide image object loaded from a file.
793 level: the level number where the size is calculated.
794
795 """
796 return (wsi.resolutions["level_dimensions"][level][1], wsi.resolutions["level_dimensions"][level][0])
797
798 def get_downsample_ratio(self, wsi, level: int) -> float:

Callers 2

__init__Method · 0.85

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…