Read whole slide images and extract patches using different backend libraries Args: backend: the name of backend whole slide image reader library, the default is cuCIM. level: the whole slide image level at which the patches are extracted. mpp: the resolution in mic
| 510 | |
| 511 | |
| 512 | class WSIReader(BaseWSIReader): |
| 513 | """ |
| 514 | Read whole slide images and extract patches using different backend libraries |
| 515 | |
| 516 | Args: |
| 517 | backend: the name of backend whole slide image reader library, the default is cuCIM. |
| 518 | level: the whole slide image level at which the patches are extracted. |
| 519 | mpp: the resolution in micron per pixel at which the patches are extracted. |
| 520 | mpp_rtol: the acceptable relative tolerance for resolution in micro per pixel. |
| 521 | mpp_atol: the acceptable absolute tolerance for resolution in micro per pixel. |
| 522 | power: the objective power at which the patches are extracted. |
| 523 | power_rtol: the acceptable relative tolerance for objective power. |
| 524 | power_atol: the acceptable absolute tolerance for objective power. |
| 525 | channel_dim: the desired dimension for color channel. Default to 0 (channel first). |
| 526 | dtype: the data type of output image. Defaults to `np.uint8`. |
| 527 | device: target device to put the extracted patch. Note that if device is "cuda"", |
| 528 | the output will be converted to torch tenor and sent to the gpu even if the dtype is numpy. |
| 529 | mode: the output image color mode, "RGB" or "RGBA". Defaults to "RGB". |
| 530 | num_workers: number of workers for multi-thread image loading (cucim backend only). |
| 531 | kwargs: additional arguments to be passed to the backend library |
| 532 | |
| 533 | Notes: |
| 534 | Only one of resolution parameters, `level`, `mpp`, or `power`, should be provided. |
| 535 | If such parameters are provided in `get_data` method, those will override the values provided here. |
| 536 | If none of them are provided here or in `get_data`, `level=0` will be used. |
| 537 | |
| 538 | """ |
| 539 | |
| 540 | supported_backends = ["cucim", "openslide", "tifffile"] |
| 541 | |
| 542 | def __init__( |
| 543 | self, |
| 544 | backend="cucim", |
| 545 | level: int | None = None, |
| 546 | mpp: float | tuple[float, float] | None = None, |
| 547 | mpp_rtol: float = 0.05, |
| 548 | mpp_atol: float = 0.0, |
| 549 | power: int | None = None, |
| 550 | power_rtol: float = 0.05, |
| 551 | power_atol: float = 0.0, |
| 552 | channel_dim: int = 0, |
| 553 | dtype: DtypeLike | torch.dtype = np.uint8, |
| 554 | device: torch.device | str | None = None, |
| 555 | mode: str = "RGB", |
| 556 | **kwargs, |
| 557 | ): |
| 558 | self.backend = backend.lower() |
| 559 | self.reader: CuCIMWSIReader | OpenSlideWSIReader | TiffFileWSIReader |
| 560 | if self.backend == "cucim": |
| 561 | self.reader = CuCIMWSIReader( |
| 562 | level=level, |
| 563 | mpp=mpp, |
| 564 | mpp_rtol=mpp_rtol, |
| 565 | mpp_atol=mpp_atol, |
| 566 | power=power, |
| 567 | power_rtol=power_rtol, |
| 568 | power_atol=power_atol, |
| 569 | channel_dim=channel_dim, |
no outgoing calls
searching dependent graphs…