Hello, I’m a student currently learning about color deconvolution methods. I was wondering how I can extract the stain matrix from an image using the Ruifrok et al. colors separation script found at this link?

My goal is to obtain the stain matrix of an H&E image and use this stain matrix in non-negative matrix factorization (NMF) to separate the stains of the image. I think I’m having some trouble understanding at which point in the Ruifrok et al. script is the stain matrix obtained from the image? From my understanding, the stain matrix is a 3x3 matrix with rows corresponding to each stain (hematoxylin, eosin, and DAB) and columns corresponding to each RGB channel.

This section of the Ruifrok et al. paper explains more about the stain matrix:

Link to image

Are these values obtained in the script or through some other procedure in the lab?

Thank you!