Read whole slide images and extract patches using TiffFile 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 f
| 1289 | |
| 1290 | @require_pkg(pkg_name="tifffile") |
| 1291 | class TiffFileWSIReader(BaseWSIReader): |
| 1292 | """ |
| 1293 | Read whole slide images and extract patches using TiffFile library. |
| 1294 | |
| 1295 | Args: |
| 1296 | level: the whole slide image level at which the patches are extracted. |
| 1297 | mpp: the resolution in micron per pixel at which the patches are extracted. |
| 1298 | mpp_rtol: the acceptable relative tolerance for resolution in micro per pixel. |
| 1299 | mpp_atol: the acceptable absolute tolerance for resolution in micro per pixel. |
| 1300 | channel_dim: the desired dimension for color channel. Default to 0 (channel first). |
| 1301 | dtype: the data type of output image. Defaults to `np.uint8`. |
| 1302 | device: target device to put the extracted patch. Note that if device is "cuda"", |
| 1303 | the output will be converted to torch tenor and sent to the gpu even if the dtype is numpy. |
| 1304 | mode: the output image color mode, "RGB" or "RGBA". Defaults to "RGB". |
| 1305 | kwargs: additional args for `tifffile.TiffFile` module. |
| 1306 | |
| 1307 | Notes: |
| 1308 | - Objective power cannot be obtained via TiffFile backend. |
| 1309 | - Only one of resolution parameters, `level` or `mpp`, should be provided. |
| 1310 | If such parameters are provided in `get_data` method, those will override the values provided here. |
| 1311 | If none of them are provided here or in `get_data`, `level=0` will be used. |
| 1312 | |
| 1313 | """ |
| 1314 | |
| 1315 | supported_suffixes = ["tif", "tiff", "svs"] |
| 1316 | backend = "tifffile" |
| 1317 | |
| 1318 | def __init__(self, **kwargs): |
| 1319 | super().__init__(**kwargs) |
| 1320 | |
| 1321 | @staticmethod |
| 1322 | def get_level_count(wsi) -> int: |
| 1323 | """ |
| 1324 | Returns the number of levels in the whole slide image. |
| 1325 | |
| 1326 | Args: |
| 1327 | wsi: a whole slide image object loaded from a file. |
| 1328 | |
| 1329 | """ |
| 1330 | return len(wsi.pages) |
| 1331 | |
| 1332 | def get_size(self, wsi, level: int) -> tuple[int, int]: |
| 1333 | """ |
| 1334 | Returns the size (height, width) of the whole slide image at a given level. |
| 1335 | |
| 1336 | Args: |
| 1337 | wsi: a whole slide image object loaded from a file. |
| 1338 | level: the level number where the size is calculated. |
| 1339 | |
| 1340 | """ |
| 1341 | return (wsi.pages[level].imagelength, wsi.pages[level].imagewidth) |
| 1342 | |
| 1343 | def get_downsample_ratio(self, wsi, level: int) -> float: |
| 1344 | """ |
| 1345 | Returns the down-sampling ratio of the whole slide image at a given level. |
| 1346 | |
| 1347 | Args: |
| 1348 | wsi: a whole slide image object loaded from a file. |
no outgoing calls
no test coverage detected
searching dependent graphs…