MorphologicalMasker¶

class MorphologicalMasker(*, mpp=None, power=None, kernel_size=None, min_region_size=None)[source]¶

Tissue masker which uses a threshold and simple morphological operations.

This method applies Otsu’s threshold before a simple small region removal, followed by a morphological dilation. The kernel for the dilation is an ellipse of radius 64/mpp unless a value is given for kernel_size. MPP is estimated from objective power via func:tiatoolbox.utils.misc.objective_power2mpp if a power argument is given instead of mpp to the initialiser.

For small region removal, the minimum area size defaults to the area of the kernel. If no mpp, objective power, or kernel_size arguments are given then the kernel defaults to a size of 1x1.

The scale of the morphological operations can also be manually specified with the kernel_size argument, for example if the automatic scale from mpp or objective power is too large or small.

Examples

>>> from tiatoolbox.tools.tissuemask import MorphologicalMasker
>>> from tiatoolbox.wsicore.wsireader import WSIReader
>>> wsi = WSIReader.open("slide.svs")
>>> thumbnail = wsi.slide_thumbnail(32, "mpp")
>>> masker = MorphologicalMasker(mpp=32)
>>> masks = masker.fit_transform([thumbnail])

An example reading a thumbnail from a file where the objective power is known:

>>> from tiatoolbox.tools.tissuemask import MorphologicalMasker
>>> from tiatoolbox.utils import imread
>>> thumbnail = imread("thumbnail.png")
>>> masker = MorphologicalMasker(power=1.25)
>>> masks = masker.fit_transform([thumbnail])

Initialise a morphological masker.

Parameters:
  • mpp (float or tuple(float)) – The microns per-pixel of the image to be masked. Used to calculate kernel_size a 64/mpp, optional.

  • power (float or tuple(float)) – The objective power of the image to be masked. Used to calculate kernel_size as 64/objective_power2mpp(power), optional.

  • kernel_size (int or tuple(int)) – Size of elliptical kernel in x and y, optional.

  • min_region_size (int) – Minimum region size in pixels to consider as foreground. Defaults to area of the kernel.

Methods

transform

Create masks using the found threshold followed by morphological operations.

transform(images)[source]¶

Create masks using the found threshold followed by morphological operations.

Parameters:
Returns:

List of images with a length 4 shape (N, height, width, channels).

Return type:

numpy.ndarray