Stain Normalizer

Digital pathology images can present strong color differences due to diverse acquisition techniques (e.g., scanners, laboratory equipment and procedures) The stain_normalizer module collects methods to transfer the staining style of an image (target) to another image (source). Stain normalization is often adopted as data standardization procedure in deep learning model training. The MacenkoStainNormalizer implements the stain normalization method proposed by Macenko et al. 1. The ReinhardStainNormalizer implements the Reinhard’s stain normalization 2.

Target image for stain normalization.
Comparison of available stain normalization techniques.


The stain normalization methods can be used to transfer the staining’s appearance of any histology image. First, we need to establish the image to be used as a style reference, and the image to be transformed accordingly:

from histolab.stain_normalizer import ReinhardStainNormalizer
from PIL import Image
target_image ="/path/target/img/img2.png")
source_image ="/path/img/to/normalize/img1.png")

The chosen stain normalization method must be first fit on the target image and then applied to the source image:

normalizer = ReinhardStainNormalizer()
normalized_img = normalizer.transform(source_image)



Macenko, Marc, et al. “A method for normalizing histology slides for quantitative analysis.” 2009 IEEE international symposium on biomedical imaging: from nano to macro. IEEE (2009)


Reinhard, Erik, et al. “Color transfer between images.” IEEE Computer graphics and applications 21.5 (2001)