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.

Usage

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 = Image.open("/path/target/img/img2.png")
target_image
https://user-images.githubusercontent.com/31658006/212924301-c80f454e-f99a-4479-9852-6ef988c078aa.png
source_image = Image.open("/path/img/to/normalize/img1.png")
source_image
https://user-images.githubusercontent.com/31658006/212924179-a85573b6-1bb3-4f9b-a8ab-00a26b1d652e.png

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

normalizer = ReinhardStainNormalizer()
normalizer.fit(target_image)
normalized_img = normalizer.transform(source_image)
normalized_img
https://user-images.githubusercontent.com/31658006/212924592-2d591852-0e3c-4f59-b821-655c793a4426.png

References

1

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)

2

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