Quantification

Module Documentation

This module performs tile-level quantification of IHC tiles, including color deconvolution, quantification of staining intensities, H-score and the IHC-Profiler score calculation, all based on antigen-specific thresholds, and masking of tumor-tissue areas.

Note

The implementation of the color-deconvolution method is based on Ruifrok & Johnston [1], and the pixel-intensity scoring is an adaptation of Varghese et al. IHC-Profiler algorithm [2].

Primary Functions

cubats.slide_collection.tile_quantification.quantify_tile(iterable)[source]

This function quantifies a single input tile and returns a dictionary.

The function offers two masking modes: tile-level masking and pixel-level masking. In tile-level masking tiles that contain sufficient tissue (mean pixel value < 230 and standard deviation > 15), will undergo stain separation and quantification. The results will be returned in the dictionary. The ‘flag’ will be set to 1. If ‘save_img’ is True the DAB image will additionally be saved in the specified directory. If the tile does not contain sufficient tissue it will not be processed and the returned dictionary will only contain the tile name and a ‘flag’ set to 0. In pixel-level masking the mask will be applied to the tile prior to quantification to receive a merged tile which will then be quantified. Non-mask pixels will be set to 255.

Parameters:

iterable (iterable) –

Iterable containing the following Information on passed tile:

  • index 0: Column, necessary for naming.

  • index 1: Row, necessary for naming.

  • index 2: Tile itself, necessary since processes cannot access shared memory.

  • DAB_TILE_DIR: Directory, for saving Image, since single processes cannot access shared memory.

  • save_img: Boolean, if True, DAB image will be saved in specified directory.

  • antigen_profile: Antigen-specific thresholds used during quantification.

  • masking_mode: Masking mode for quantification.

Returns:

Dictionary containing tile results:

  • Tilename (str): Name of the tile.

  • Histogram (ndarray): Histogram of the tile.

  • Hist_centers (ndarray): Centers of histogram bins.

  • Zones (ndarray): Number of pixels in each intensity zone.

  • Percentage (ndarray): Percentage of pixels in each zone.

  • Score (ndarray): Score for the tile.

  • Tissue Count (int): Total number of tissue pixels in the tile.

  • Flag (int): Processing flag (1 if processed, 0 if not).

  • Image Array (ndarray): Array of pixel values for positive pixels.

Return type:

dict

Internal Functions

cubats.slide_collection.tile_quantification.color_deconvolution(ihc_rgb, hematoxylin=False, eosin=False)[source]

Separates individual stains (Hematoxylin, Eosin, DAB) from an IHC image and returns an image for each stain.

Parameters:
  • ihc_rgb (Image) – IHC image in RGB format.

  • hematoxylin (bool) – If True, returns Hematoxylin image as well. Defaults to False.

  • eosin (bool) – If True, returns Eosin image. Defaults to False.

Returns:

A tuple containing:
  • ihc_d (Image): DAB (3’,3’-Diaminobenzidine) stain of the image.

  • ihc_h (Image): Hematoxylin stain of the image if hematoxylin=True, otherwise None.

  • ihc_e (Image): Eosin stain of the image if eosin=True, otherwise None.

Return type:

tuple

cubats.slide_collection.tile_quantification.evaluate_staining_intensities(image, antigen_profile, tumor_mask=None)[source]

Calculates pixel intensity of each pixel in the input image and separates them into 5 different zones based on their intensity. The image is converted to grayscale format, resulting in a distribution of intensity values between 0-255. Intensities above 235 are predominantly background or fatty tissues and do not contribute to pathological scoring. Thresholds for high-positive, medium-positive, low-positive and negative pixels are defined by the passed antigen profile. If ‘masking_mode’ is ‘pixel-level’, pixels with an intensity value of 255 will be excluded as they mark non-mask areas. After calculating pixel intensities this function calculates percentage contribution of each of the zones with respect to the mask tissue in the tile, as well as the a pathology score.

Parameters:
  • image (xp.ndarray) – Input image.

  • antigen_profile (dict) – Dictionary with threshold values.

  • tumor_mask (xp.ndarray)

Returns:

A tuple containing:
  • hist (ndarray): Histogram of the image.

  • hist_centers (ndarray): Centers of histogram bins.

  • zones (xp.ndarray): Number of pixels in each intensity zone with respect to the tumor mask.

  • percentage (xp.ndarray): Percentage of pixels in each intensity zone with respect to the tumor mask.

  • score (str): Overall score of the tile.

  • maskcount (int): Tissue count for tile-level masking. Count of masked pixels for pixel-level.

  • img_analysis (xp.ndarray): Array of pixel values for multi-antigen evaluation.

Return type:

tuple

cubats.slide_collection.tile_quantification.calculate_percentage_and_score(zones)[source]

Calculates the percentage of pixels in each zone relative to the tissue count (Positive tissues) and total mask count (Background) and computes a score for each zone. If more than 66.6% of the total pixels are attributed to a single zone, that zone’s score is assigned. Else, the score for each zone is calculated using this formula:

\[\text{Score} = \frac{(\text{number of pixels in zone} \times \text{weight of zone})}{\text{total pixels in image}}\]

with weights 4 for the high positive zone, 3 for the positive zone, 2 for the low positive zone, 1 for the negative zone, and 0 for the background. The final score is the maximum score among all zones.

Parameters:

zones (xp.ndarray) – Array containing amount of pixels from each zone

Returns:

A tuple containing:
  • percentage (xp.ndarray): Array containing the percentage of pixels in each zone.

  • score (str): Name of the zone if it exceeds 66.6%, otherwise the name of the zone with the highest score.

Return type:

tuple

Raises:

ValueError – If all zones have zero pixels.

cubats.slide_collection.tile_quantification.mask_tile(tile, mask)[source]

Masks the tile with the given mask. The mask is a binary image with the same dimensions as the tile. The function returns the masked tile as an Image, containing the tile where the mask is positive and white where it is negative.

Parameters:
  • tile (Image) – Tile to be masked

  • mask (Image) – Mask to be applied to the tile

Returns:

Masked tile

Return type:

Image

References