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

Method get_mpp

monai/data/wsi_reader.py:1359–1393  ·  view source on GitHub ↗

Returns the micro-per-pixel resolution of the whole slide image at a given level. Args: wsi: a whole slide image object loaded from a file. level: the level number where the mpp is calculated.

(self, wsi, level: int)

Source from the content-addressed store, hash-verified

1357 return str(abspath(wsi.filehandle.path))
1358
1359 def get_mpp(self, wsi, level: int) -> tuple[float, float]:
1360 """
1361 Returns the micro-per-pixel resolution of the whole slide image at a given level.
1362
1363 Args:
1364 wsi: a whole slide image object loaded from a file.
1365 level: the level number where the mpp is calculated.
1366
1367 """
1368 if (
1369 "XResolution" in wsi.pages[level].tags
1370 and "YResolution" in wsi.pages[level].tags
1371 and wsi.pages[level].tags["XResolution"].value
1372 and wsi.pages[level].tags["YResolution"].value
1373 ):
1374 unit = wsi.pages[level].tags.get("ResolutionUnit")
1375 if unit is not None:
1376 unit = str(unit.value.name)
1377 if unit is None or len(unit) == 0:
1378 warnings.warn("The resolution unit is missing. `micrometer` will be used as default.")
1379 unit = "micrometer"
1380
1381 convert_to_micron = ConvertUnits(unit, "micrometer")
1382
1383 # Here, x and y resolutions are rational numbers so each of them is represented by a tuple.
1384 yres = wsi.pages[level].tags["YResolution"].value
1385 xres = wsi.pages[level].tags["XResolution"].value
1386 if xres[0] and yres[0]:
1387 return convert_to_micron(yres[1] / yres[0]), convert_to_micron(xres[1] / xres[0])
1388 else:
1389 raise ValueError(
1390 "The `XResolution` and/or `YResolution` property of the image is zero, "
1391 "which is needed to obtain `mpp` for this file. Please use `level` instead."
1392 )
1393 raise ValueError("`mpp` cannot be obtained for this file. Please use `level` instead.")
1394
1395 def get_wsi_at_mpp(
1396 self, wsi, mpp: float | tuple[float, float], atol: float = 0.00, rtol: float = 0.05

Callers 1

get_wsi_at_mppMethod · 0.95

Calls 2

ConvertUnitsClass · 0.90
getMethod · 0.80

Tested by

no test coverage detected