overlay_mask
overlay_mask(image, mask, colormap, alpha=OVERLAY_ALPHA)
An image with a mask tinted onto it.
Parameters
| image |
np.ndarray |
one image, height x width x channels, 0-1 floats or 0-255 integers. |
required |
| mask |
np.ndarray |
a prediction for it - one-hot or probabilities, height x width x classes - or an array of class indices. |
required |
| colormap |
list[tuple[int, int, int]] |
one colour per class, darkest first, as the specification gives it. |
required |
| alpha |
float |
how much of the tint shows. The default keeps the tissue legible underneath, which is the point of an overlay. |
OVERLAY_ALPHA |
Returns
|
np.ndarray |
A height x width x 3 array of 0-255 integers, which is what the R |
|
np.ndarray |
overlay_mask() returns too. |
Raises
|
PlatypusError |
if the image cannot be drawn, or the mask does not cover it. |
import numpy as np image = np.full((4, 4, 3), 0.5) mask = np.zeros((4, 4, 2)); mask[1:3, 1:3, 1] = 1 shown = overlay_mask(image, mask, [(0, 0, 0), (255, 0, 0)]) shown.shape, shown.dtype ((4, 4, 3), dtype(‘uint8’)) bool((shown[1, 1] != shown[0, 0]).any()) True