plot_masks

plot_masks(
    images,
    prediction=None,
    truth=None,
    colormap=None,
    which=None,
    alpha=OVERLAY_ALPHA,
    labels=None,
    slice=None,
)

Images, their masks and where the two disagree, one row per image.

The columns are the ones the R plot_masks() draws, in the same order and for the same reason: the image, the truth, the prediction, and the agreement only when both are given, because agreement between a prediction and nothing is not defined.

Parameters

Name Type Description Default
images np.ndarray one image or a stack, [image] x height x width x channels. required
prediction np.ndarray | None one-hot or probabilities per image, or class indices. None
truth np.ndarray | None the annotation, same shapes. None
colormap list[tuple[int, int, int]] | None one colour per class, darkest first. The default is black and white, the two-class case, which is also what R defaults to. None
which list[int] | None which images to draw. The default is the first four, because a montage of forty is not a figure anybody reads. None
alpha float how much of the tint shows. OVERLAY_ALPHA
labels list[str] | None a row label each. The default numbers them. None
slice int | str | None which plane of a volume to draw, or "middle". Required for volumes and refused for images, because a volume shown as one picture is either a lie or a projection nobody asked for. Volumes arrive as a stack, rank 5. None

Returns

Name Type Description
Figure A matplotlib Figure. Never shown and never saved - the caller decides.

Raises

Name Type Description
PlatypusError if a volume is given without a slice, a slice without a volume, or a mask whose classes the colormap has no colours for.

import numpy as np image = np.full((1, 8, 8, 3), 0.5) mask = np.zeros((1, 8, 8, 2)); mask[0, 2:5, 2:5, 1] = 1 figure = plot_masks(image, prediction=mask, truth=mask, colormap=[(0, 0, 0), (255, 0, 0)]) [axis.get_title() for axis in figure.axes] [‘image’, ‘truth’, ‘prediction’, ‘agreement’]