SegmentationMask<T>

Models & Types · AiDotNet.Augmentation.Image

Represents a segmentation mask for pixel-level annotations.

For Beginners

While a bounding box draws a rectangle around an object, a segmentation mask precisely outlines the object’s shape. When you rotate or flip an image, the mask must be transformed identically.

How It Works

Segmentation masks provide pixel-level object delineation, used for:

  • Semantic segmentation (what class is each pixel)
  • Instance segmentation (which object instance is each pixel)
  • Panoptic segmentation (both semantic and instance)

Constructors

Constructor Summary
SegmentationMask() Creates an empty segmentation mask.
SegmentationMask(IList<IList<ValueTuple<double, double>>> polygons, int width, int height, MaskType type) Creates a segmentation mask from polygon vertices.
SegmentationMask(T[] maskData, MaskType type, int classIndex) Creates a segmentation mask from dense data.
SegmentationMask(int[] rleCounts, int width, int height, MaskType type) Creates a segmentation mask from polygon vertices.

Properties

Property Summary
IDictionary<string, object> Metadata { get; set; } Gets or sets additional metadata.
IList<IList<ValueTuple<double, double>>> Polygons { get; set; } Gets or sets the polygon vertices (if using polygon encoding).
MaskEncoding Encoding { get; set; } Gets or sets the current encoding format.
MaskType Type { get; set; } Gets or sets the mask type.
T Confidence { get; set; } Gets or sets the confidence score (if from a segmenter).
T[] MaskData { get; set; } Gets or sets the mask data as a 2D array [height, width].
int ClassIndex { get; set; } Gets or sets the class index (for semantic/instance masks).
int Height { get; set; } Gets or sets the mask height.
int InstanceId { get; set; } Gets or sets the instance ID (for instance/panoptic masks).
int Width { get; set; } Gets or sets the mask width.
int[] RLECounts { get; set; } Gets or sets the RLE-encoded mask (if using RLE encoding).
string ClassName { get; set; } Gets or sets the class name.

Methods

Method Summary
SegmentationMask<T> Clone() Creates a deep copy of this mask.
T[] ToDense() Converts this mask to dense format.
ValueTuple<int, int, int, int> GetBoundingBox() Calculates the bounding box of the mask.
double Dice(SegmentationMask<T> other) Calculates the Dice coefficient with another mask.
double IoU(SegmentationMask<T> other) Calculates the IoU (Intersection over Union) with another mask.
int Area() Calculates the area (number of foreground pixels).
int[] ToRLE() Converts this mask to RLE format.