Peter554 / StainTools

Tools for tissue image stain normalisation and augmentation in Python 3
MIT License
321 stars 107 forks source link

Principal Eigen vectors inversion, based on the principal eigen vector #31

Closed dimimal closed 5 years ago

dimimal commented 5 years ago

Thank you for open sourcing your code. I have a question regarding the two lines of code below. Why you inversed the eigen vectors based on the principal eigen vector's values?

# Make sure vectors are pointing the right way
        if V[0, 0] < 0: V[:, 0] *= -1
        if V[0, 1] < 0: V[:, 1] *= -1
Peter554 commented 5 years ago

The eigenvectors physically correspond to color vectors in optical density space so they should be elementwise positive. The math doesn't know about this (if x is an eigenvector so is -x). So we have to see if we got the negative one and if so invert. Does that make sense?

dimimal commented 5 years ago

Yes @Peter554. But we are flipping the vectors based on the direction of the principal vector. Is there something else that i miss? For example, why we are not taking the absolute value of the whole V array and we just flip the other vectors based on the principal vector's direction?

Peter554 commented 5 years ago

The eigenvectors are columns of that matrix not rows. So there is no special treatment for the principle eigenvector. I only test one element of the vector as that's enough to check if it points the right way.

dimimal commented 5 years ago

@Peter554 Thanks for your help. Could you please provide the macenko stain normalized samples to cross check them with mine? I saw only the original on your drive.

dimimal commented 5 years ago

@Peter554 I would be obliged if you can send me by email the normalized samples you have on your website. My email is: dimimallios@gmail.com

Kind regards, Dimitris