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.
| Type | What each pixel receives | Separates instances | Typical use |
|---|---|---|---|
| Semantic segmentation | A class label | No | Land cover maps, road scenes |
| Instance segmentation | An object identity and class | Yes, countable objects only | Counting people, picking items |
| Panoptic segmentation | Class plus identity where relevant | Yes, and labels background | Full scene understanding |
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.
| Architecture | Key idea | Typical strength |
|---|---|---|
| Fully convolutional network | Replaces dense layers with convolutions | First end-to-end pixel prediction |
| U-Net | Symmetric encoder-decoder with skips | Medical images, small datasets |
| DeepLab family | Dilated convolutions, multi-scale pooling | Semantic scene parsing |
| Mask R-CNN | Detect boxes, then predict masks | Instance segmentation |
| Mask transformers | Predict a set of masks directly | Unified semantic, instance, panoptic |
| Promptable models | Masks from clicks, boxes or text | Interactive and zero-shot use |
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.
| Task | Output | Spatial precision | Annotation effort |
|---|---|---|---|
| Image classification | One label per image | None | Lowest |
| Object detection | Boxes with labels | Approximate | Moderate |
| Image segmentation | Pixel-level masks | Exact outlines | Highest |
| Pose estimation | Keypoints on a body | Selected points | Moderate |
| OCR | Recognized text and positions | Text regions | Moderate |
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.
| Metric | Definition in brief | Typical use |
|---|---|---|
| Intersection over union | Overlap area divided by union area | General semantic segmentation |
| Mean IoU | IoU averaged over classes | Benchmark comparison |
| Dice coefficient | Twice overlap divided by total area | Medical imaging |
| Mask average precision | Precision across IoU thresholds | Instance segmentation |
| Panoptic quality | Combines matching and mask quality | Panoptic segmentation |
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.