Segmentation

What the Task Does

Image segmentation assigns labels to pixels, producing a dense spatial map rather than one image label or a set of boxes. It can recover object shapes, region boundaries, and the layout of an entire scene.

This precision supports medical imaging, autonomous driving, satellite analysis, and industrial inspection, where a coarse bounding box may include too much irrelevant area.

Core Idea

For an input of height HH and width WW, a segmentation model predicts an output aligned to the same spatial grid. In semantic segmentation with CC classes, the logits commonly have shape H×W×CH\times W\times C.

Each pixel receives a class prediction, but useful results also require context. A local patch may be ambiguous, so models combine fine spatial detail with broader features that describe objects and scenes.

Main Variants

Semantic Segmentation

Semantic segmentation assigns a class to every pixel but does not distinguish separate objects of the same class. All car pixels, for example, share one category.

Instance Segmentation

Instance segmentation gives each countable object its own mask and class. Two adjacent cars therefore remain separate instances. Mask R-CNN is a well-known two-stage example.

Panoptic Segmentation

Panoptic segmentation combines both views. Countable thing classes such as people receive instance IDs, while amorphous stuff classes such as sky and road receive semantic labels.

Type Pixel classes Separate same-class objects Typical use
Semantic Yes No Scene parsing, medical imaging
Instance Yes Yes Counting, object-level analysis
Panoptic Yes For thing classes Complete scene interpretation

How It Works

Encode Context

An encoder downsamples the image while extracting increasingly semantic features. This expands the receptive field and reduces compute, but it also removes precise location and boundary information.

Recover Spatial Detail

A decoder upsamples the representation to a pixel-aligned output. Skip connections transfer high-resolution encoder features into the decoder, helping restore edges and small structures lost during downsampling.

U-Net uses a symmetric encoder-decoder with skip connections. DeepLab uses dilated convolutions and Atrous Spatial Pyramid Pooling for multi-scale context. Mask R-CNN adds a per-instance mask branch to a two-stage detector.

Promptable foundation models such as Segment Anything produce masks from points, boxes, or other prompts. They change how masks are requested, but deployment still requires validation on the target domain.

Learn Dense Predictions

Semantic models often optimize per-pixel cross-entropy, Dice loss, or a combination. Instance models additionally learn object proposals, classes, boxes, and mask assignments.

Class weighting or region-aware losses can prevent large background regions from dominating small foreground structures.

How It Is Evaluated

For one class, Intersection over Union is

IoU⁡=TPTP+FP+FN.\operatorname{IoU}=\frac{TP}{TP+FP+FN}.

Mean IoU averages class-level IoU values. The Dice coefficient places twice the overlap in the numerator:

Dice⁡=2TP2TP+FP+FN.\operatorname{Dice}=\frac{2TP}{2TP+FP+FN}.

Dice is common in medical imaging, especially for small foreground regions. Boundary IoU and boundary F-scores focus on edge quality, where ordinary region metrics may hide visibly poor contours.

Instance segmentation commonly uses mask AP across IoU thresholds. Panoptic Quality combines recognition quality with the overlap quality of matched segments.

Practical Considerations

  • Use a pretrained encoder when dense labels are scarce.
  • Apply crops, flips, color changes, and geometric transforms consistently to images and masks.
  • Preserve enough input and feature-map resolution for the smallest important structure.
  • Address imbalance with weighted cross-entropy, Dice-style losses, sampling, or region-aware objectives.
  • Define annotation rules for uncertain edges, holes, overlaps, and objects cut by image boundaries.

Limitations and Failure Modes

  • Pixel-level annotation is expensive and boundaries can be subjective or inconsistent.
  • Downsampling can erase thin structures and small objects before the decoder can recover them.
  • Class imbalance lets a strong background score conceal poor foreground performance.
  • Models may produce fragmented masks, merged adjacent instances, or over-smoothed boundaries.
  • Post-processing can improve contours but adds parameters and may fail under a domain shift.

Related