Image segmentation

On this page 7

Image segmentation is the computer vision task of assigning a label to every pixel of an image, so that the image is divided into regions that correspond to object classes, individual objects or meaningful parts. Its output is a mask that follows the exact outline of each region, rather than the rectangular box produced by object detection.

Within artificial intelligence, segmentation is the method of choice whenever shape, area or precise boundaries matter: measuring a tumor on a scan, separating road from sidewalk for a vehicle, cutting a product out of a photo or counting cells under a microscope.

Types of image segmentation

Segmentation comes in three main forms that differ in whether they separate individual objects and whether they cover the whole image. Choosing the right form is the first decision in any segmentation project.

TypeWhat each pixel receivesSeparates instancesTypical use
Semantic segmentationA class labelNoLand cover maps, road scenes
Instance segmentationAn object identity and classYes, countable objects onlyCounting people, picking items
Panoptic segmentationClass plus identity where relevantYes, and labels backgroundFull scene understanding
Main segmentation tasks

Semantic segmentation labels all cars simply as car, while instance segmentation distinguishes car one from car two. Panoptic segmentation combines both: countable objects such as people and cars receive individual identities, while amorphous regions such as sky, grass or road receive class labels only.

A newer category, promptable segmentation, produces a mask for whatever a user indicates with a click, a box or a text phrase. Such foundation models are trained on very large mask collections and can segment objects they were never explicitly trained to recognize.

How segmentation models work

Most segmentation networks follow an encoder-decoder design. The encoder, a convolutional network or a vision transformer, compresses the image into rich but low-resolution features. The decoder then upsamples those features back to full resolution and predicts a label for every pixel.

Recovering fine boundaries is the core difficulty, because downsampling discards spatial detail. Architectures address it with skip connections that pass high-resolution features directly to the decoder, as in U-Net, with dilated convolutions that enlarge the receptive field without reducing resolution, or with mask-based transformer decoders that predict a set of masks and their classes.

ArchitectureKey ideaTypical strength
Fully convolutional networkReplaces dense layers with convolutionsFirst end-to-end pixel prediction
U-NetSymmetric encoder-decoder with skipsMedical images, small datasets
DeepLab familyDilated convolutions, multi-scale poolingSemantic scene parsing
Mask R-CNNDetect boxes, then predict masksInstance segmentation
Mask transformersPredict a set of masks directlyUnified semantic, instance, panoptic
Promptable modelsMasks from clicks, boxes or textInteractive and zero-shot use
Influential segmentation architectures

Segmentation compared with other vision tasks

Segmentation sits at the finest level of spatial detail among common computer vision tasks. Finer output carries a higher cost in annotation and computation.

TaskOutputSpatial precisionAnnotation effort
Image classificationOne label per imageNoneLowest
Object detectionBoxes with labelsApproximateModerate
Image segmentationPixel-level masksExact outlinesHighest
Pose estimationKeypoints on a bodySelected pointsModerate
OCRRecognized text and positionsText regionsModerate
Image segmentation and neighboring tasks

Tasks are often combined. An OCR pipeline may first segment text regions, and a robotics system may detect objects and then segment them to compute grasp points. Object detection is usually sufficient when only position and count matter, while segmentation is justified when outline, area or overlap must be known.

Measuring segmentation quality

Segmentation is evaluated by comparing predicted masks with ground-truth masks. The standard metrics all measure overlap between the two regions in slightly different ways.

MetricDefinition in briefTypical use
Intersection over unionOverlap area divided by union areaGeneral semantic segmentation
Mean IoUIoU averaged over classesBenchmark comparison
Dice coefficientTwice overlap divided by total areaMedical imaging
Mask average precisionPrecision across IoU thresholdsInstance segmentation
Panoptic qualityCombines matching and mask qualityPanoptic segmentation
Standard segmentation metrics

Pixel accuracy alone is misleading: if background covers 95 percent of an image, a model that predicts only background still scores 95 percent. Class-averaged metrics and boundary-focused measures give a more honest picture, especially for small structures.

Practical challenges and pitfalls

The largest practical cost of segmentation is pixel-accurate annotation, which can take minutes per image for complex scenes and requires domain experts in fields such as radiology. Promptable models now speed up labeling considerably by proposing masks that annotators only correct.

  • Class imbalance: thin or small structures are underweighted; Dice or focal losses help.
  • Boundary errors: resolution loss blurs edges, which matters for measurement tasks.
  • Domain shift: models trained on one scanner, camera or season degrade on another.
  • Inconsistent labels: annotators disagree on exact outlines, which caps achievable accuracy.
  • Compute at high resolution: full-resolution masks strain memory on large images.

Tiling large images, augmenting with realistic variations and reviewing errors by class are the most dependable ways to improve a segmentation model once data volume is adequate.

In simple terms

Image segmentation is like coloring a picture in a coloring book, where every area gets the right color: blue for sky, green for trees, gray for the road. The computer decides which object or area each tiny dot of the picture belongs to.

This is more precise than drawing a box around an object. A box around a person also contains bits of background, but a segmentation mask follows the exact outline, which is essential when the shape or size of something really matters.

A practical example

An agricultural research team uses drone images to estimate crop health across 2,000 hectares of farmland. Each image is about 5,000 by 4,000 pixels, so they split images into tiles of 1,024 pixels and train a semantic segmentation model with four classes: healthy crop, stressed crop, bare soil and weeds.

Annotators label 600 tiles with help from a promptable model that proposes masks, cutting labeling time substantially. Early results show strong scores for bare soil but weak results for weeds, which cover small scattered patches. Switching to a Dice-based loss and adding more weed examples raises the weed class IoU noticeably.

The final maps let agronomists calculate the exact area of stressed crop per field and direct spraying only where weeds appear, reducing chemical use compared with uniform treatment.