Comments (2)
@lester0866 I had this happen, too.
It happened for an image that was very "white". This led staintools to see each pixel as a 'background pixel'. It then creates a mask, since it only transforms non-background pixels.
This way, you can end up with 0 or 1 pixel that's left as non-background.
If it then tries to compute the eigenvalues of this 'matrix', this is not possible.
My solution was to change macenko_stain_extractor.MacenkoStainExtractor
to
tissue_mask = LuminosityThresholdTissueLocator.get_tissue_mask(I, luminosity_threshold=luminosity_threshold).reshape((-1,))
OD = convert_RGB_to_OD(I).reshape((-1, 3))
OD = OD[tissue_mask]
# Yoni's edit!!
if tissue_mask.sum() <= 1: # If the tissue mask has 0 or 1 pixel the linalg does not work. We will return an untransformed image
return False
# Eigenvectors of cov in OD space (orthogonal as cov symmetric)
_, V = np.linalg.eigh(np.cov(OD, rowvar=False))
And then, in stain_normalizer.StainNormalizer
:
def transform(self, I, filename=''):
"""
Transform an image.
:param I: Image RGB uint8.
:return:
"""
stain_matrix_source = self.extractor.get_stain_matrix(I)
# Yoni's edit: get_strain_matrix returns false if the linalg doesn't work out. If that doesn't work out, we return an untransformed image
if isinstance(stain_matrix_source, np.ndarray):
source_concentrations = get_concentrations(I, stain_matrix_source, multiThread=False)
maxC_source = np.percentile(source_concentrations, 99, axis=0).reshape((1, 2))
source_concentrations *= (self.maxC_target / maxC_source)
tmp = 255 * np.exp(-1 * np.dot(source_concentrations, self.stain_matrix_target))
return tmp.reshape(I.shape).astype(np.uint8)
else:
print(f"=== This image was seen as background by Macenko method, and is therefore not transformed: {filename}")
return I.astype(np.uint8)
I hope this helps out anyone with these issues
from staintools.
@YoniSchirris I did what you suggested but i am having another error, i don't know why !
The error:
Epoch 1/100 /content/src/staintools/staintools/stain_normalizer.py:43: RuntimeWarning: divide by zero encountered in true_divide source_concentrations *= (self.maxC_target / maxC_source) /content/src/staintools/staintools/stain_normalizer.py:43: RuntimeWarning: invalid value encountered in multiply source_concentrations *= (self.maxC_target / maxC_source)
from staintools.
Related Issues (20)
- ModuleNotFoundError after installation HOT 3
- Make `pip install` great again (2) pip install documentation? HOT 1
- Floating point exception (core dumped) HOT 13
- Negative optical density issue HOT 1
- About stain normalization speed..... HOT 1
- Principal Eigen vectors inversion, based on the principal eigen vector HOT 5
- Pip install broken HOT 7
- AssertionError: Negative optical density. HOT 10
- The software stops when have a empty tissue image when I tried to process hundreds of images HOT 3
- AttributeError: module 'staintools' has no attribute 'BrightnessStandardizer' HOT 2
- Copyright and usage question HOT 2
- ModuleNotFoundError after installation HOT 1
- Failed building wheel for spams HOT 1
- bad_array_new_length via vahadane/macenko on very large image
- MultiProcessing HOT 3
- omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
- GPU accelerate?
- Question about Normalization for Immunohistochemical Stainings
- Problem of using StainTools for a tensor input
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from staintools.