:py:mod:`wsinfer.patchlib.patch` ================================ .. py:module:: wsinfer.patchlib.patch Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: wsinfer.patchlib.patch.temporary_recursion_limit wsinfer.patchlib.patch.get_multipolygon_from_binary_arr wsinfer.patchlib.patch.get_patch_coordinates_within_polygon Attributes ~~~~~~~~~~ .. autoapisummary:: wsinfer.patchlib.patch.logger .. py:data:: logger .. py:function:: temporary_recursion_limit(limit: int) -> Iterator[None] .. py:function:: 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 Create a Shapely Polygon from a binary array. :param arr: Binary array where non-zero values indicate presence of tissue. :type arr: array :param scale: If specified, this is the factor by which coordinates are multiplied to recover the coordinates at the base resolution of the whole slide image. :type scale: tuple of two floats, optional :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. .. py:function:: 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_] Get coordinates of patches within a polygon. :param slide_width: The width of the slide in pixels at base resolution. :type slide_width: int :param slide_height: The height of the slide in pixels at base resolution. :type slide_height: int :param patch_size: The size of a patch in pixels. :type patch_size: int :param half_patch_size: Half of the length of a patch in pixels. :type half_patch_size: int :param polygon: A shapely Polygon representing the presence of tissue. :type polygon: Polygon :param overlap: 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. :type overlap: float :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). :rtype: coordinates