Image Segmentation

GATE Relevance: Medium

🎯 Learning Objectives

  • Distinguish semantic, instance, and panoptic segmentation
  • Understand FCN and the encoder-decoder paradigm
  • Explain U-Net architecture and the role of skip connections in segmentation
  • Describe transposed (deconvolution) and dilated (atrous) convolutions
  • Know the DeepLab family and Mask R-CNN
  • Compute mIoU, pixel accuracy, and Dice coefficient

1. Types of Image Segmentation

Semantic Segmentation: Assign a class label to every pixel in the image. All pixels belonging to “car” get the same label regardless of which car. No distinction between individual object instances.
Instance Segmentation: Detect each object instance and produce a pixel-level mask for it. Two cars are labelled as “car-1” and “car-2” with separate masks. Combines detection + segmentation.
Panoptic Segmentation: Unifies semantic and instance segmentation. Every pixel gets a class label, and countable object instances (“things”) additionally get an instance ID. Uncountable regions (“stuff” like sky, road) receive only class labels.
PropertySemanticInstancePanoptic
Pixel-level class✔✔✔
Instance-level ID✘✔✔ (things only)
Background/stuff✔✘✔
Example modelFCN, DeepLabMask R-CNNPanoptic FPN

2. FCN (Fully Convolutional Networks)

The first major deep-learning approach to semantic segmentation (Long et al., 2015). Key idea: replace FC layers in a classification CNN with 1×1 convolutions to preserve spatial information, then upsample to the original resolution.

Why Fully Convolutional? FC layers destroy spatial layout (flatten to 1-D). By converting them to 1×1 convolutions, every layer maintains a 2-D spatial grid, enabling pixel-wise classification. The network can also accept inputs of any size.

FCN Variants

  • FCN-32s: Single 32× upsampling from the final feature map. Coarse output.
  • FCN-16s: Combines predictions from the final and pool4 layers using a skip connection, then 16× upsampling. Finer boundaries.
  • FCN-8s: Adds pool3 predictions via another skip. Best boundary quality among FCN variants.

3. Encoder-Decoder Structure

The dominant paradigm in segmentation networks:

Encoder: A series of convolution + pooling layers that progressively reduce spatial resolution while increasing the number of feature channels. Captures what is in the image (semantic content).

Decoder: Gradually recovers spatial resolution through upsampling operations (transposed convolutions or bilinear interpolation). Reconstructs where objects are (spatial detail).

The encoder typically uses a pre-trained classification backbone (e.g., ResNet, VGG). The decoder is trained to map low-resolution feature maps back to full-resolution pixel labels.

4. Transposed Convolution (Deconvolution)

The standard learned upsampling operation in segmentation networks. Despite the name “deconvolution,” it is not the mathematical inverse of convolution.

Transposed Convolution: An upsampling operation that inserts zeros between input elements, then applies a standard convolution. Equivalently, it maps each input element to a k×k patch in the output and sums overlapping contributions.
Transposed Conv Output Size:
O = (n − 1) × s − 2p + k
Where n = input size, s = stride, p = padding, k = kernel size. Note this is the “inverse” of the standard formula.

Example — Transposed Conv Output

Input: 7 × 7, kernel: 4 × 4, stride: 2, padding: 1

O = (7 − 1) × 2 − 2(1) + 4 = 12 − 2 + 4 = 14 × 14

This doubles the spatial resolution (7 → 14), commonly used in decoder paths.

⚠ Checkerboard Artifacts: Transposed convolutions can produce checkerboard patterns when kernel size is not divisible by stride. Mitigation: use bilinear upsampling followed by a regular convolution, or choose kernel/stride carefully (e.g., k = 2s).

5. Atrous / Dilated Convolution

Increases the receptive field without reducing spatial resolution or increasing the number of parameters.

Dilated Convolution: Inserts gaps (holes, “atrous” from French “à trous”) between kernel elements. A dilation rate r = 2 spaces kernel weights 2 pixels apart, giving a 3×3 kernel an effective receptive field of 5×5 with only 9 parameters.
Effective Kernel Size: keff = k + (k − 1)(r − 1)
For k = 3, r = 2: keff = 3 + 2(1) = 5.
For k = 3, r = 4: keff = 3 + 2(3) = 9.

Advantage: Maintains spatial resolution (no pooling needed) while capturing multi-scale context. Critical for dense prediction tasks like segmentation.

6. U-Net Architecture

Designed for biomedical image segmentation (Ronneberger et al., 2015). The U-shaped architecture has become one of the most influential designs in segmentation.

U-Net Key Feature — Skip Connections: The encoder and decoder are connected at each resolution level by skip connections that concatenate encoder feature maps with decoder feature maps. This provides the decoder with both high-level semantic information (from the bottleneck) and low-level spatial detail (from the encoder).

U-Net Architecture (simplified)

StagePathResolutionChannelsOperation
1Encoder572 → 5681 → 642 × Conv3, ReLU
2Encoder284 → 28064 → 128MaxPool, 2 × Conv3
3Encoder140 → 136128 → 256MaxPool, 2 × Conv3
4Encoder68 → 64256 → 512MaxPool, 2 × Conv3
5Bottleneck32 → 28512 → 1024MaxPool, 2 × Conv3
6Decoder56 (after concat)1024 → 512UpConv, concat, 2 × Conv3
7Decoder104512 → 256UpConv, concat, 2 × Conv3
8Decoder200256 → 128UpConv, concat, 2 × Conv3
9Decoder388128 → 64UpConv, concat, 2 × Conv3
Output—38864 → C1 × 1 Conv

Key insight: Concatenation (not addition as in ResNet) doubles the channel count at each skip, giving the decoder access to the full encoder features at matching resolution.

7. DeepLab Family

Series of models from Google that use atrous convolutions and Atrous Spatial Pyramid Pooling (ASPP) for multi-scale segmentation.

ASPP (Atrous Spatial Pyramid Pooling): Apply dilated convolutions with multiple dilation rates (e.g., r = 6, 12, 18) in parallel, plus a 1×1 conv and global average pooling. Concatenate all outputs. Captures objects at multiple scales without losing resolution.

DeepLab Versions

  • DeepLab v1: Atrous convolution + CRF post-processing
  • DeepLab v2: Added ASPP for multi-scale context
  • DeepLab v3: Improved ASPP with batch normalisation + global average pooling branch
  • DeepLab v3+: Added a decoder module for sharper boundaries (encoder-decoder with ASPP)

8. Mask R-CNN

Extends Faster R-CNN for instance segmentation by adding a mask prediction branch parallel to the existing classification and bounding box regression branches.

Mask R-CNN Architecture:
  1. Backbone CNN + FPN (Feature Pyramid Network)
  2. RPN generates region proposals
  3. RoI Align (not RoI Pooling) extracts features — uses bilinear interpolation for sub-pixel precision
  4. Three parallel heads: classification, box regression, and mask prediction (small FCN per RoI)
RoI Align vs RoI Pooling: RoI Pooling quantises coordinates to integer positions, causing misalignment. RoI Align uses bilinear interpolation at exact floating-point positions, which is critical for pixel-accurate mask prediction.

9. Evaluation Metrics

Pixel Accuracy: Fraction of correctly classified pixels:
PA = ∑i pii / ∑i∑j pij
where pij = number of pixels of class i predicted as class j. Simple but can be misleading with class imbalance.
Mean IoU (mIoU): For each class c, compute IoUc = TPc / (TPc + FPc + FNc), then average over all classes:
mIoU = (1/C) ∑c=1C IoUc
The standard metric for semantic segmentation.
Dice Coefficient (F1 Score for segmentation):
Dice = 2|A ∩ B| / (|A| + |B|) = 2TP / (2TP + FP + FN)
Ranges from 0 to 1. Equivalent to the F1 score. Widely used in medical image segmentation.

Worked Example — mIoU

Binary segmentation (class 0 = background, class 1 = object). Confusion matrix:

Pred 0Pred 1
True 0800 (TN)50 (FP)
True 130 (FN)120 (TP)

IoU0 (background) = 800 / (800 + 50 + 30) = 800 / 880 = 0.909

IoU1 (object) = 120 / (120 + 50 + 30) = 120 / 200 = 0.600

mIoU = (0.909 + 0.600) / 2 = 0.755

Dice for object class = 2 × 120 / (2 × 120 + 50 + 30) = 240 / 320 = 0.750

⚠ Class Imbalance: Pixel accuracy is biased toward dominant classes (e.g., background). Always use mIoU or Dice when classes are imbalanced.

10. Summary

  • Semantic segmentation labels every pixel but does not distinguish instances.
  • Instance segmentation (Mask R-CNN) assigns per-object masks.
  • FCN replaced FC layers with 1×1 convolutions for dense prediction.
  • U-Net uses an encoder-decoder with skip concatenation; dominant in medical imaging.
  • Transposed convolution is the standard learnable upsampling. Output: (n−1)s − 2p + k.
  • Dilated convolution increases receptive field without reducing resolution. Effective kernel = k + (k−1)(r−1).
  • DeepLab uses ASPP for multi-scale context; v3+ adds a decoder.
  • mIoU is the standard metric; Dice is preferred in medical imaging.