What is image segmentation?
Image segmentation is the computer vision task of assigning a label to every pixel in an image. Semantic segmentation labels each pixel with a class, such as road or sky. Instance segmentation also separates individual objects of the same class, so two cars get two different masks.
Segmentation is used where exact shapes matter: outlining tumors and organs in medical scans, finding drivable road and lane markings for self-driving cars, mapping land cover from satellite images, and cutting out people for portrait mode and video backgrounds. Most models follow an encoder-decoder design such as U-Net, and promptable models like Segment Anything now produce masks for objects they were never trained on.
Key ideas
- Segmentation predicts a class for every pixel, so the output has the same height and width as the image.
- Semantic segmentation labels classes, and instance segmentation also separates individual objects.
- An encoder downsamples to gather context, and a decoder upsamples back to full resolution.
- Skip connections pass fine spatial detail from the encoder straight to the decoder.
- Mean IoU across classes is the standard evaluation metric.
- Upsampling can be fixed, as in nearest or bilinear, or learned, as in transposed convolution.
Common questions
What is the difference between Dice and IoU?
Both measure the overlap between a predicted mask A and a true mask B. IoU is |A ∩ B| / |A ∪ B|, and Dice is 2|A ∩ B| / (|A| + |B|), so Dice = 2·IoU / (1 + IoU) and is always at least as large. Dice loss, 1 − Dice, is popular in medical imaging because small structures still count fully even when background dominates the image.
How much labeled data does a segmentation model need?
Pixel labels are slow to make, so most projects start from an encoder pretrained on ImageNet or COCO and fine-tune on a few hundred to a few thousand masks. Heavy augmentation stretches small datasets further, as in the original U-Net. Promptable models such as Segment Anything also speed up labeling by drafting masks for a human to correct.
Can transformers do image segmentation?
Yes. SegFormer pairs a hierarchical transformer encoder with a light decoder for semantic segmentation. Mask2Former treats semantic, instance and panoptic segmentation as predicting a set of masks with a transformer decoder, and one architecture handles all three.
What is the difference between segmentation and image matting?
Segmentation gives each pixel a hard label: a pixel is either in the person or not. Matting estimates a soft opacity value between 0 and 1 for every pixel, which captures hair, fur and motion blur at the edges. Portrait-mode and background-removal tools often run segmentation first, then refine the boundary with matting.
Related explainers
- Object Detection — Locate and classify multiple objects in an image using bounding boxes and confidence scores
- Convolutional Neural Networks — How CNNs see and understand images
- Skip Connections & ResNets — Residual learning and why deeper networks work
- Pooling & Downsampling — Reduce spatial dimensions while preserving the most important features in feature maps
- Diffusion Models — Generate images by learning to reverse a gradual noising process
- Data Augmentation — Artificially expand training data with transformed copies to reduce overfitting
References
- Ronneberger, Fischer & Brox (2015), "U-Net: Convolutional Networks for Biomedical Image Segmentation"
- Long, Shelhamer & Darrell (2015), "Fully Convolutional Networks for Semantic Segmentation", CVPR
- He, Gkioxari, Dollár & Girshick (2017), "Mask R-CNN", ICCV
- Kirillov et al. (2023), "Segment Anything"
- Odena, Dumoulin & Olah (2016), "Deconvolution and Checkerboard Artifacts", Distill
Last updated