overlay_probability_map¶
- overlay_probability_map(img, prediction, alpha=0.35, colour_map='jet', 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. Assumed to be HW.
prediction (ndarray) – 2D prediction map. Values are expected to be between 0-1.
alpha (float) – Opacity value used for the overlay.
colour_map (string) – The colour map to use for the heatmap. jet is used as the default.
min_val (float) – Only consider pixels that are greater than or equal to min_val. Otherwise, the original WSI in those regions will be displayed.
alpha – Opacity value used for the overlay.
ax (ax) – Matplotlib axis 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_probability_map >>> 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) >>> probability_map = np.random.rand(256, 256).astype(np.float32) >>> # Example usage of overlay_probability_map >>> ax = overlay_probability_map( ... img=img, ... prediction=probability_map, ... alpha=0.35, ... colour_map="jet", ... min_val=0.0, ... ax=None, ... return_ax=True, ... ) >>> plt.show()