Skip to main content
. 2019 Sep 30;6:193. doi: 10.3389/fmed.2019.00193

Algorithm 1.

The Macenko stain normalization algorithm.

1: Convert RGB to optical density (OD)
2: Remove pixels with negligible optical density
3: Apply SVD on the OD tuples and use the largest 2 values to create the SVD plane
4: Project data onto the plane and normalize to unit length
5: Calculate the angle ϕ of each point with respect to the 1st (or 2nd) SVD direction
6: Find the robust extremes (αth and (100−α)th percentiles) of the angle ϕ
7: Find the projection of the extreme values back to OD space
8: Use this projection as optical density matrix (ODM)
9: Calculate the individual stain concentrations (Ch and Ce) using the inverse of ODM
10: Find the robust maximum ((100 − α)th percentiles) of the individual stain concentrations Ch, Ce
11: Normalize and transform concentrations to OD space and then back to RGB using an H&E template