Normalization¶
Abstract base classes¶
Normalizer abstract base classes
-
class
staintools.normalization.normalizer_abc.
FancyNormalizer
(**kwargs)[source]¶ Abstract class for a ‘fancy’ normalizer (inherits from Normalizer). Adds methods for stain matrix and source concentration estimation.
-
fetch_target_stains
()[source]¶ Fetch the target stain matrix and convert from OD to RGB. Must call fit first (this builds the stain matrix).
Returns:
-
static
get_concentrations
(I, stain_matrix, lamda=0.01)[source]¶ Get the concentration matrix. Suppose the input image is H x W x 3 (uint8). Define Npix = H * W. Then the concentration matrix is Npix x 2 (or we could reshape to H x W x 2). The first element of each row is the Hematoxylin concentration. The second element of each row is the Eosin concentration.
We do this by ‘solving’ OD = C*S (Matrix product) where OD is optical density (Npix x 3), C is concentration (Npix x 2) and S is stain matrix (2 x 3). See docs for spams.lasso.
We restrict the concentrations to be positive and penalise very large concentration values, so that background pixels (which can not easily be expressed in the Hematoxylin-Eosin basis) have low concentration and thus appear white.
Parameters: - I – Image. A np array HxWx3 of type uint8.
- stain_matrix – a 2x3 stain matrix. First row is Hematoxylin stain vector, second row is Eosin stain vector.
Returns: The Nx2 concentration matrix, where N=H*W is number of pixels.
-
Reinhard method¶
-
class
staintools.normalization.reinhard.
ReinhardNormalizer
(**kwargs)[source]¶ Normalize a patch stain to the target image using the method of: 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.
-
get_mean_std
(I)[source]¶ Get mean and standard deviation of each channel.
Parameters: I – Image RGB uint8. Returns:
-
static
lab_split
(I)[source]¶ Convert from RGB uint8 to LAB and split into channels.
Parameters: I – Image RGB uint8. Returns:
-
Macenko method¶
-
class
staintools.normalization.macenko.
MacenkoNormalizer
(**kwargs)[source]¶ Stain normalization based on the method of: 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 method¶
-
class
staintools.normalization.vahadane.
VahadaneNormalizer
(**kwargs)[source]¶ Stain normalization inspired by method of: 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.