torch_staintools.functional.tissue_mask package

Module contents

exception torch_staintools.functional.tissue_mask.TissueMaskException

Bases: Exception

torch_staintools.functional.tissue_mask.get_tissue_mask(image: Tensor, luminosity_threshold=0.8, throw_error: bool = True, true_when_empty: bool = False) Tensor

Get a binary mask where true denotes pixels with a luminosity less than the specified threshold.

Typically, we use to identify tissue in the image and exclude the bright white background. If luminosity_threshold is None then entire image region is considered as tissue

Parameters:
  • image – RGB [0, 1]. -> BCHW

  • luminosity_threshold – threshold of luminosity in range of [0, 1]. Pixels with intensity within (0, threshold) are considered as tissue. If None then all pixels are considered as tissue, effectively bypass this step.

  • throw_error – whether to throw error

  • true_when_empty – if True, then return an all-True mask if no tissue are detected. Effectively bypass the tissue detection. Note that in certain cases, both Vahadane and Macenko may either obtain low quality results or even crash if the nearly entire input image is background.

Returns:

mask (B1HW)