The mask annotation renderer keeps compressed RLE masks semantic in detection
frames. BaseMaskStyle controls the visible fill, global opacity, outline, and
render mode while the browser package privately prepares efficient artifacts.
import { StrokeAlignment } from "supervision";
session.setPresentation({
renderers: [
annotationRenderers.mask({
style: new BaseMaskStyle({
fillAlpha: 1,
opacity: 0.72,
stroke: {
alpha: 1,
width: 2,
widthUnit: "screen",
alignment: StrokeAlignment.Outside,
},
}),
}),
],
});
opacity applies to the complete mask layer and can be updated cheaply.
fillAlpha is part of prepared fill styling and remains separate so an outline
can stay opaque. Use widthUnit: "screen" for outlines measured in CSS pixels,
like box outlines, with the same thickness through zoom and across mask
resolutions. The renderer prepares the pixel boundaries once, including holes
and disconnected components, without changing the semantic mask. Use
widthUnit: "mask" to retain the source-mask-pixel radius, with the total
outline spanning twice that radius and scaling with the fitted media and zoom.
With widthUnit omitted, stroke.width is the total outline width in CSS
pixels, drawn by the prepared mask shader. A width of 1 stays
one screen pixel across fitted media sizes and camera zoom; fractional coverage
can distribute that width over adjacent pixels. stroke.alignment defaults to
Outside, preserving the mask interior. Choose Center or Inside to split
the outline across the boundary or place it inside.
This corrects the previous default, where mask widths grew on both sides of the boundary and scaled with the fitted media. Existing outlines can therefore appear thinner and move outward. Browser rendering bounds the outline to 16 mask texels per side; very small fitted media can reach that limit and show a narrower outline.
Set annotationAntialiasing: true to smooth mask boundaries alongside the other
annotation layers. Use 2 to preserve more mask detail up to the original
resolution before smoothing. Categorical picking continues to read exact
detection IDs. The 2× capture increases preparation work and cache bytes within
the configured budget. See
Smooth Annotation Edges.
See Detections And Rendering for the semantic-mask and prepared-artifact boundary.
By default, masks draw below vector geometry. Set renderer.maskOrder when
creating the session to interleave masks with boxes, polygons and other retained
shapes:
const session = await createMediaSession({
container,
media,
detections,
renderer: {
maskOrder: "detection",
interaction: { preferTopmost: true },
},
});
Higher Detection.zIndex draws in front. Missing values use the detection's
frame index, and equal values follow frame order. Each mask preserves its own
coverage, so transparent overlaps reveal lower detections and holes remain
transparent. preferTopmost makes pointer picking follow this same stack.
Labels and interaction overlays keep their established positions above it.
This mode retains independent cropped mask coverage and one active texture per
mask. Omit maskOrder to keep the dense mask layer used by existing sessions.