overlay_prediction_mask¶
- overlay_prediction_mask(img, prediction, alpha=0.35, label_info=None, min_val=0.0, ax=None, *, return_ax)[source]¶
Generate an overlay, given a 2D prediction map.
- Parameters:
img (ndarray) – Input image to overlay the results on top of.
prediction (ndarray) – 2D prediction map. Multi-class prediction should have values ranging from 0 to N-1, where N is the number of classes.
label_info (dict) – A dictionary containing the mapping for each integer value within prediction to its string and color. [int] : (str, (int, int, int)). By default, integer will be taken as label and color will be random.
min_val (float) – Only consider predictions greater than or equal to min_val. Otherwise, the original WSI in those regions will be displayed.
alpha (float) – Opacity value used for the overlay.
ax (ax) – Matplotlib ax object.
return_ax (bool) – Whether to return the matplotlib ax object. If not, then the overlay array will be returned.
- Returns:
If return_ax is True, return the matplotlib ax object. Else, return the overlay array.
- Return type:
np.ndarray | Axes
Examples
>>> from tiatoolbox.utils.visualization import overlay_prediction_mask >>> import numpy as np >>> from matplotlib import pyplot as plt >>> # Generate a random example; replace with your own data >>> img = np.random.randint(0, 256, size=(256, 256, 3), dtype=np.uint8) >>> prediction = np.random.randint(0, 3, size=(256, 256), dtype=np.uint8) >>> label_info = { ... 0: ("Background", (0, 0, 0)), ... 1: ("Tumor", (255, 0, 0)), ... 2: ("Stroma", (0, 255, 0)) ... } >>> # Example usage of overlay_prediction_mask >>> ax = overlay_prediction_mask( ... img=img, ... prediction=prediction, ... alpha=0.5, ... label_info=label_info, ... min_val=0.0, ... ax=None, ... return_ax=True ... ) >>> plt.show()