wsinfer.patchlib.patch#

Attributes#

Functions#

temporary_recursion_limit(→ Iterator[None])

get_multipolygon_from_binary_arr(...)

Create a Shapely Polygon from a binary array.

get_patch_coordinates_within_polygon(...)

Get coordinates of patches within a polygon.

Module Contents#

wsinfer.patchlib.patch.logger[source]#
wsinfer.patchlib.patch.temporary_recursion_limit(limit: int) Iterator[None][source]#
wsinfer.patchlib.patch.get_multipolygon_from_binary_arr(arr: numpy.typing.NDArray[numpy.int_], scale: tuple[float, float] | None = None) tuple[shapely.MultiPolygon, Sequence[numpy.typing.NDArray[numpy.int_]], numpy.typing.NDArray[numpy.int_]] | None[source]#

Create a Shapely Polygon from a binary array.

Parameters:
  • arr (array) – Binary array where non-zero values indicate presence of tissue.

  • scale (tuple of two floats, optional) – If specified, this is the factor by which coordinates are multiplied to recover the coordinates at the base resolution of the whole slide image.

Returns:

  • polygon – A shapely MultiPolygon object representing tissue regions.

  • contours – A sequence of arrays representing unscaled contours of tissue.

  • hierarchy – An array of the hierarchy of contours.

wsinfer.patchlib.patch.get_patch_coordinates_within_polygon(slide_width: int, slide_height: int, patch_size: int, half_patch_size: int, polygon: shapely.Polygon, overlap: float = 0.0) numpy.typing.NDArray[numpy.int_][source]#

Get coordinates of patches within a polygon.

Parameters:
  • slide_width (int) – The width of the slide in pixels at base resolution.

  • slide_height (int) – The height of the slide in pixels at base resolution.

  • patch_size (int) – The size of a patch in pixels.

  • half_patch_size (int) – Half of the length of a patch in pixels.

  • polygon (Polygon) – A shapely Polygon representing the presence of tissue.

  • overlap (float) – The proportion of the patch_size to overlap. A value of 0.5 would have an overlap of 50%. A value of 0.2 would have an overlap of 20%. Negative values will add space between patches. A value of -1 would skip every other patch. Value must be in (-inf, 1). The default value of 0.0 produces non-overlapping patches.

Returns:

Array with shape (N, 2), where N is the number of tiles. Each row in this array contains the coordinates of the top-left of a tile: (minx, miny).

Return type:

coordinates