Skip to content
17 changes: 16 additions & 1 deletion tiatoolbox/tools/stainextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
from sklearn.decomposition import DictionaryLearning

from tiatoolbox import logger
from tiatoolbox.utils.misc import get_luminosity_tissue_mask
from tiatoolbox.utils.transforms import rgb2od

Expand Down Expand Up @@ -238,6 +239,12 @@ class VahadaneExtractor:
This class contains code inspired by StainTools
[https://github.com/Peter554/StainTools] written by Peter Byfield.

.. warning::
Vahadane stain extraction/normalization algorithms are unstable
after the update to `dictionary learning` algorithm in
scikit-learn > v0.23.0 (see issue #382). Please be advised and
consider using other stain extraction (normalization) algorithms.

Args:
luminosity_threshold (float):
Threshold used for tissue area selection.
Expand All @@ -259,6 +266,14 @@ def __init__(
regularizer: float = 0.1,
) -> None:
"""Initialize :class:`VahadaneExtractor`."""
# Issue a warning about the algorithm's stability
logger.warning(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mostafajahanifar Please can you add links to alternatives as discussed during the meeting?

"Vahadane stain extraction/normalization algorithms are unstable "
"after the update to `dictionary learning` algorithm in "
"scikit-learn > v0.23.0 (see issue #382). Please be advised and "
"consider using other stain extraction (normalization) algorithms.",
stacklevel=2,
)
self.__luminosity_threshold = luminosity_threshold
self.__regularizer = regularizer

Expand All @@ -267,7 +282,7 @@ def get_stain_matrix(self: VahadaneExtractor, img: np.ndarray) -> np.ndarray:

Args:
img (:class:`numpy.ndarray`):
Input image used for stain matrix estimation
Input image used for stain matrix estimation.

Returns:
:class:`numpy.ndarray`:
Expand Down