cellmil.utils.stain_normalization

Functions

RGB_to_OD(img[, light_intensity])

Converts an RGB array to OD.

macenko_normalization(patches[, beta, ...])

Normalizes the stain appareance of the patches using Macenko.

Classes

NormalizeParameters()

Macenko Stain Normalization.

class cellmil.utils.stain_normalization.NormalizeParameters[source]

Bases: object

Macenko Stain Normalization.

Contains vectors used as reference for the Macenko normalization. The H&E reference matrix should have shape (3, 2) where the rows are RGB positions and the columns are the two components (first column Haematoxylin, second column Eosin). The maximum saturation (stain concentration) should have shape (2, 1) and it represents the maximum saturation/concentration that the Haematoxylin and Eosin will have in optical density before the conversion to RGB.

__init__() None[source]
get_he_ref() ndarray[Any, Any][source]

Returns the reference H&E vector.

Returns:

A (3, 2) ndarray representing some reference values for a H&E WSI

Return type:

np.ndarray

get_max_sat() ndarray[Any, Any][source]

Returns the maximum saturation.

Returns:

A (2, 1) ndarray representing the desired maximum saturation.

Return type:

np.ndarray

cellmil.utils.stain_normalization.macenko_normalization(patches: List[ndarray[Any, Any]], beta: float = 0.15, alpha: int = 1, light_intensity: int = 255) Tuple[List[ndarray[Any, Any]], Union[None, ndarray[Any, Any]], Union[None, ndarray[Any, Any]]][source]

Normalizes the stain appareance of the patches using Macenko.

References:

  • A method for normalizing histology slides for quantitative analysis. M. Macenko et al.,

ISBI 2009 - https://github.com/schaugf/HEnorm_python/blob/master/normalizeStaining.py - https://github.com/CODAIT/deep-histopath/blob/c8baf8d47b6c08c0f6c7b1fb6d5dd6b77e711c33/ deephistopath/preprocessing.py - https://towardsdatascience.com/stain-estimation-on-microscopy-whole-slide-images-2b5a57062268

param patches:

A list of patches

type patches:

List[np.ndarray]

param beta:

Which portion of the transparent values should be removed. Defaults to 0.15.

type beta:

float, optional

param alpha:

Which percentiles of the values to consider (alpha, 1 - alpha). Defaults to 1.

type alpha:

int, optional

param light_intensity:

The highest luminosity value. Defaults to 255.

type light_intensity:

int, optional

param normalization_vector_path:

Path to a normalization file (needs to be a json file). Defaults to None.

type normalization_vector_path:

Union[Path, str], optional

returns:
A stained-normalized list of patches,

the mixing stain vectors and the 99th percentile saturation vectors

rtype:

Tuple[List[np.ndarray], Union[None, np.ndarray], Union[None, np.ndarray]]

cellmil.utils.stain_normalization.RGB_to_OD(img: ndarray[Any, Any], light_intensity: int = 255) ndarray[Any, Any][source]

Converts an RGB array to OD.

Parameters:
  • img (np.ndarray) – An RGB array

  • light_intensity (int, optional) – The highest luminosity value. Defaults to 255.

Returns:

The optical density array

Return type:

np.ndarray