SegmentationRenderer
Helpers & Utilities · AiDotNet.ComputerVision.Segmentation.Common
Draws segmentation masks over an image, producing an overlay image tensor.
For Beginners
A segmentation model tells you which pixels belong to which object, but that answer is a grid of numbers. This turns it into something you can actually look at: the original image with each detected region tinted a distinct colour, optionally outlined.
How It Works
Shape of the API. The primary entry point mirrors
torchvision.utils.draw_segmentation_masks(image, masks, alpha, colors) — a free function
taking the image, the masks and the render settings, returning a new image tensor. Visualization
is an evaluation-time concern, so nothing here holds state or needs to be configured in advance.
The SegmentationVisualizationConfig overload exists because this library’s config
carries knobs torchvision has no equivalent for (contours, palettes, score thresholds).
Value range is preserved. The image may be in [0, 1] or [0, 255]; the range is detected and the output is returned in the SAME range as the input. Silently changing an image’s scale is the kind of defect that only surfaces as a washed-out or saturated picture much later.
This is post-processing over a produced result, not a training path, so it indexes tensors
directly rather than going through Engine ops — consistent with SegmentationTensorOps.
No gradient ever flows through a visualization.
Methods
| Method | Summary |
|---|---|
Tensor<T> DrawSegmentationMasks(Tensor<T> image, Tensor<T> masks, SegmentationVisualizationConfig config) |
Draws masks honouring a full SegmentationVisualizationConfig. |
Tensor<T> DrawSegmentationMasks(Tensor<T> image, Tensor<T> masks, double alpha, byte[] colors) |
Draws boolean masks over an image. |
Tensor<T> Render(Tensor<T> image, SegmentationOutput<T> output, SegmentationVisualizationConfig config) |
Renders a whole SegmentationOutput over an image, choosing the right source automatically: instance masks when present, otherwise the per-pixel class map. |
double DetectImageScale(Tensor<T> image) |
Detects whether an image tensor uses normalized [0,1] values or 8-bit-style [0,255] values. |
Fields
| Field | Summary |
|---|---|
double DefaultAlpha |
Default alpha, matching torchvision’s draw_segmentation_masks. |