Skip to content

Ritacheta/Stain_Normalization

 
 

Repository files navigation

  • Overview
  • Some simple examples
  • More challenging images

Overview

Implementation of a few common stain normalization techniques (Reinhard, Macenko, Vahadane) in Python (3.5).

For usage see the notebook demo.ipynb

In short do something like (all techniques have the same API, where we create a stain normalization object or Normalizer. The fit and transform methods are then the most important).

n = stainNorm_Reinhard.Normalizer()
n.fit(target_image)
out = n.transform(source_image)

If you want Hematoxylin do something like

n = stainNorm_Vahadane.Normalizer()
out = n.hematoxylin(source_image)

We can also view the stains seperated by e.g.

n = stainNorm_Vahadane.Normalizer()
n.fit(target_image)
stain_utils.show_colors(n.target_stains())

We use the SPAMS (SPArse Modeling Software) package. Use with Python via e.g https://anaconda.org/conda-forge/python-spams

Below we show the application of the techniques to a few images (in data folder). We normalize to the first image and for Macenko and Vahadane also show the extracted Hematoxylin channel. Below that are a few more challenging images (also in data folder). All images are taken from the ICIAR 2018 challenge.

One change to the vanilla methods is used. With all images we first apply a brightness standardizing step (below). This is especially useful in handling the more challenging images (which are typically too dim) and does not damage performance for the other images.

def standardize_brightness(I):
    """

    :param I:
    :return:
    """
    p = np.percentile(I, 90)
    return np.clip(I * 255.0 / p, 0, 255).astype(np.uint8)

Some simple examples

Original images

Reinhard

E. Reinhard, M. Adhikhmin, B. Gooch, and P. Shirley, ‘Color transfer between images’, IEEE Computer Graphics and Applications, vol. 21, no. 5, pp. 34–41, Sep. 2001.

Macenko

M. Macenko et al., ‘A method for normalizing histology slides for quantitative analysis’, in 2009 IEEE International Symposium on Biomedical Imaging: From Nano to Macro, 2009, pp. 1107–1110.

Vahadane

A. Vahadane et al., ‘Structure-Preserving Color Normalization and Sparse Stain Separation for Histological Images’, IEEE Transactions on Medical Imaging, vol. 35, no. 8, pp. 1962–1971, Aug. 2016.

More challenging images

Original images

Reinhard

Macenko

Vahadane

About

Some stain normalization code

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Jupyter Notebook 99.9%
  • Python 0.1%