Image segmentation assigns a label to every pixel in an image, so that pixels sharing a label share some property, such as a class or an object identity. This article groups today’s methods into four families. Classical algorithms (thresholding, region growing, watershed, graph partitioning) work from intensity and neighbourhood rules. Convolutional networks (FCN, U-Net, DeepLab) learn per-pixel classes. Detection-based and unified models (Mask R-CNN, MaskFormer) separate individual objects. Promptable foundation models (the SAM family) segment whatever a click, box or phrase points at. Which family fits depends less on benchmark rank than on three things: the output you need, the labelled data you have, and the error your downstream process can tolerate.
Semantic, instance and panoptic segmentation produce different outputs
Before comparing methods, pin down which output the task needs, because the three task types produce different outputs. Semantic segmentation gives every pixel a class, so all the people in a crowd share one label. Instance segmentation tells each person apart as a separate object. Panoptic segmentation does both: it labels every pixel with a class and also separates instances of the same class. Kirillov and colleagues introduced panoptic segmentation together with a dedicated metric, panoptic quality (PQ), to score it. Our explainer on panoptic segmentation and how it differs from instance and semantic covers the “stuff versus things” distinction in more detail.
The choice has consequences downstream. A rule that measures the total area of corrosion on a plate only needs semantic output. A rule that counts separate scratches, or rejects a part when any single defect exceeds a size limit, needs instances.
How do thresholding, region growing, watershed and graph cuts compare with learned models?
Some classical methods, such as histogram-based thresholding and Felzenszwalb’s graph method, are fast. Their weakness is that results hinge on hand-set choices, such as the threshold or similarity criterion, and are influenced by noise. Learned models instead learn features automatically from labelled data rather than relying on hand-engineered ones.
The main classical families each fail in their own way:
- Thresholding turns a grey-scale image into a binary one using a clip level. Everything depends on choosing that threshold, whether by Otsu’s maximum-variance method, maximum entropy, balanced histogram thresholding or k-means.
- Region growing assumes that neighbouring pixels in a region have similar values and merges them when a similarity criterion holds. The choice of criterion matters a great deal, and noise affects the result in every case.
- Watershed treats the gradient magnitude as a landscape, and pixels draining to the same local minimum form one segment. Run naively, it over-segments because of noise and irregularities, which is why OpenCV implements a marker-based variant: you label pixels you are sure are foreground, pixels you are sure are background, and leave the uncertain band at zero.
- Graph partitioning models the image as a weighted undirected graph, with edge weights encoding similarity between neighbours, and cuts it according to a criterion for “good” clusters. Felzenszwalb’s graph-based method has a single scale parameter, yet the actual size and number of segments still vary widely with local contrast.
The scikit-image documentation is frank about where these algorithms sit now. Good segmentations are hard to obtain and “good” depends on the application, so these methods are usually run to produce an over-segmentation into superpixels, which then feed more sophisticated algorithms such as conditional random fields. That is a useful way to think about classical segmentation today: often a pre-processing or post-processing stage rather than the whole answer.
The structural limit is the hand-chosen features themselves. The survey by Ghosh and colleagues (2019) notes that classical approaches depend on features chosen by domain experts, who tend to miss latent or abstract features, whereas deep learning learns features automatically. Even so, O’Mahony and colleagues argue that classical techniques have not become obsolete, and they review hybrid methods that improve performance and tackle problems unsuited to deep learning. Our article on feature extraction and image processing in computer vision covers that classical layer, and the benefits of classical computer vision sets out where it still earns its place in production.
If lighting, fixturing and contrast are controlled and the target is defined by intensity, start with a tuned threshold or a marker-based watershed. If the target varies in texture or shape in ways nobody can write down, learn it.
CNN architectures behind modern image segmentation
Convolutional networks reached state-of-the-art semantic segmentation in 2015. The fully convolutional network (FCN) removed the fully connected layers of a classification CNN to keep spatial information. It reached 62.7% mean IoU on PASCAL VOC 2011, about 10% better than the previous best (SDS), and cut inference time by 286x.
Several architectures that followed add ways to recover detail lost to downsampling:
- U-Net pairs an encoder that captures context with a decoder that upsamples, and adds skip connections between layers of the same shape so that fine detail survives. It was first built to find cell boundaries in biomedical images.
- DeepLab uses atrous (dilated) convolution to widen the field of view without adding parameters or computation. Its ASPP module probes features at several sampling rates to capture objects at multiple scales. A fully connected CRF on top added 3-5% absolute mean IoU, and the system reached 79.7% mIoU on the PASCAL VOC 2012 test set. The DCNN part ran at 8 FPS on an NVIDIA Titan X, while CRF inference took 0.5 seconds on a CPU.
- Mask R-CNN extends the Faster R-CNN detector with a parallel branch that predicts a mask for each detected object, which makes it an instance segmentation model. Its authors report that it adds only a small overhead and runs at 5 fps.
- MaskFormer treats semantic and instance segmentation as one mask-classification problem with the same model, loss and training procedure, and also handles panoptic segmentation. Transformer-based segmenters like this connect to the broader question of vision transformers versus CNN detectors.
The DeepLab authors report one failure themselves. Their model fails to capture delicate boundaries of objects such as bicycles and chairs, and the CRF cannot recover them because the unary term is not confident enough. They suggest that an encoder-decoder structure with high-resolution decoder features may help. For inspection work, where defects are often thin, that limitation matters more than a headline mIoU.
How have promptable foundation models changed image segmentation?
Promptable models changed the interface. Traditional frameworks such as FCN and Mask R-CNN are not promptable. A promptable model instead generates a mask from a prompt that says what to segment, and it can adapt to new tasks zero-shot (SAM, SEEM) or few-shot (SegGPT). A 2024 survey of segmentation in the foundation-model era groups promptable segmentation by prompt type. Interactive segmentation takes clicks, scribbles, boxes or polygons. Referring segmentation takes a linguistic phrase. Few-shot segmentation takes a handful of annotated image-mask pairs.
SAM, SAM 2 and SAM 3 are dedicated segmentation foundation models. SAM 2 is reported by its authors to be more accurate and 6x faster than SAM on images, and it adds a streaming memory for video. SAM 3 moves to concept prompts (short noun phrases, image exemplars or both) and returns masks and identities for every matching instance. The SAM 3 authors report that it doubles the accuracy of existing systems on this concept segmentation task.
Three limits keep these models from being a default answer:
- They are spatial specialists. The 2024 survey notes that CLIP excels at semantic understanding while SAM and DINO specialise in spatial understanding, which is why many approaches combine them. SAM can be turned into an instance segmenter by feeding it boxes from a detector such as Faster R-CNN or Grounding DINO.
- They are heavy. The same survey says most foundation-model segmentation methods carry significant computational overhead, from heavy image encoders to costly fine-tuning, and points to distillation, compression and parameter-efficient tuning as the open work.
- They degrade on specialised imagery. On 12 medical datasets, SAM’s Dice overlaps were significantly lower than those of five dedicated clinical imaging segmentation models, by 0.1-0.5 and in some cases 0.6-0.7 Dice. SAM did better on 2D images, larger targets and higher foreground-background contrast. Ji and colleagues (2023) reached a similar conclusion across agriculture, manufacturing, remote sensing and healthcare, under a title that sums it up: segment anything is not always perfect.
Once segmentation moves from single images to video, masks have to be associated across frames. That mechanism is covered in segmentation tracking in automotive perception: per-frame masks versus cross-frame association.
How is the quality of a segmentation measured, and where do IoU and Dice mislead?
Intersection over Union (IoU) is the overlap between the predicted mask and the ground truth divided by their union. It runs from 0 (no agreement) to 1 (full agreement). The Dice score is twice the intersection divided by the sum of the two mask areas. An IoU of 0.5 therefore corresponds to a Dice of about 0.67, so a mask’s Dice is never lower than its IoU. Multi-class results are usually reported as mean Dice or mean IoU across classes.
The problem is what these metrics ignore. IoU measures pixel agreement regardless of how those pixels are grouped into regions. Pixel-wise metrics therefore hide over-segmentation (one true region split into several predictions) and under-segmentation (one prediction covering several true regions). Zhang and colleagues show a prediction that finds only 2 of 6 people while keeping pixel error low, and chair legs split into separate regions that suggest several chairs. Their comparison of three models makes the point in numbers. DeepLabv3 had a lower mIoU error than ESPNetv2 (0.18 against 0.25), yet a slightly worse under-segmentation score (RUM 0.32 against 0.30). Average precision and panoptic quality do not separate the two error types either.
Metric quick reference
| Metric | What it rewards | What it misses |
|---|---|---|
| IoU / mIoU | Pixel overlap with ground truth | Whether regions are split or merged |
| Dice | Pixel overlap, weighted towards the intersection | The same region errors as IoU, since it comes from the same counts |
| AP (COCO style) | Region matches above IoU thresholds from 0.50 to 0.95 | How severe the over-segmentation is |
| Panoptic quality | Joint pixel and region error, penalising false positive and false negative regions | Which of over- or under-segmentation caused the error |
| ROM / RUM | Over- and under-segmentation, measured separately | Pixel accuracy, so report it alongside a pixel metric |
Pick the metric from the downstream consequence. The Metrics Reloaded consortium found that metrics in biomedical image analysis often fail to reflect the domain interest, and built a “problem fingerprint” framework for problem-aware metric choice. For counting defects, a region-level error matters more than a point of mIoU.
Comparing two segmentation models properly
A higher mean Dice on one test set is not, by itself, proof that a model is better. Jaakkola and colleagues (2024) recommend non-parametric tests such as the Wilcoxon signed-rank test, because the paired t-test underestimates variance under resampling such as repeated cross-validation. The Wilcoxon test compares per-image Dice or IoU values across a reasonable number of images. In their own experiment, neither the Dice nor the IoU values were normally distributed.
Choosing a segmentation method for surface-defect inspection
Defective samples are scarce, annotation is time-consuming, and defects are small against high-resolution images. TechnoLynx Computer Vision R&D turns a method choice like the one below into a validated segmentation pipeline that runs at line rate on your hardware.
Tabernik and colleagues (2019) built a two-stage segmentation-and-decision network for surface cracks that learned from about 25-30 defective samples rather than hundreds or thousands. With 5-pixel dilated annotations it reached 99.9% average precision, with zero false positives and one false negative. Coarse annotations reached 99.7% AP, with minimal or no loss against finer labels. At a zero-miss operating point it flagged 3 of 399 images for manual review, against 68 for DeepLabv3+ and 108 for U-Net. The authors attribute U-Net’s weakness to its 45-pixel receptive field (against 205 for their network) and DeepLabv3+’s to overfitting from too many parameters. That is one dataset of electrical commutators, so read it as proof that small-data segmentation can work, not as a ranking that carries over to your parts.
Three further findings shape the choice:
- Segmentation is not always the right framing. The same authors note that complex 3D parts with broken or missing components may suit detection methods such as Mask R-CNN better.
- Unsupervised anomaly segmentation has its own benchmark. MVTec AD contains 5354 high-resolution images across 15 categories with 73 defect types, trains on defect-free images only, and provides pixel-precise ground truth. In its baseline study no method performed consistently well across all categories, and a high ROC AUC sometimes came with poor region overlap because the threshold, set from defect-free images alone, was wrong.
- SAM out of the box is not enough. An evaluation on strip steel, tile and rail defects against 13 specialised models found that SAM could not achieve satisfactory performance in complex industrial scenes.
Latency closes the loop. Tabernik’s network took 110 ms per full-resolution image and 33 ms at half resolution, while the commercial Cognex ViDi Suite ran at 10 ms. AutoRTNet-A reported 72.2% mIoU at 110 FPS on the Cityscapes street-scene test set, at 768×1536 input on an NVIDIA TitanXP. Line rate, not accuracy alone, often decides between architectures.
Decision guide for defect segmentation
| Situation | Starting point | Why |
|---|---|---|
| Defects separable by grey level | Thresholding or marker-based watershed | A threshold turns grey-scale into binary; markers control over-segmentation |
| Tens of labelled defects | Supervised segmentation network trained on coarse labels | Learned from 25-30 defects; coarse labels close to fine |
| Almost no defect examples | Anomaly segmentation trained on good parts, benchmarked MVTec-style | Training uses defect-free images; threshold choice is the risk |
| Missing or broken parts on 3D assemblies | Instance detection such as Mask R-CNN | Not well framed as pixel segmentation |
| Complex industrial surface-defect scenes (steel, tile, rail) | Not a SAM-family model out of the box | Unsatisfactory on complex industrial scenes |
Our article on instance segmentation models for manufacturing inspection goes further into the instance-level route.
Published results such as ROC AUC show whether a method’s anomaly maps represent defects. They cannot tell you where to set the operating point for your reject cost, and that has to be measured on your own parts.
FAQ
What are the four methods of segmentation?
This article groups methods into four families: classical, convolutional, detection-based and unified, and promptable. Classical methods include thresholding, edge-based methods (which need closed boundaries), region growing and clustering such as k-means.