Image Segmentation
🎯 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
| Property | Semantic | Instance | Panoptic |
|---|---|---|---|
| Pixel-level class | ✔ | ✔ | ✔ |
| Instance-level ID | ✘ | ✔ | ✔ (things only) |
| Background/stuff | ✔ | ✘ | ✔ |
| Example model | FCN, DeepLab | Mask R-CNN | Panoptic 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.
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:
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.
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.
5. Atrous / Dilated Convolution
Increases the receptive field without reducing spatial resolution or increasing the number of parameters.
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 Architecture (simplified)
| Stage | Path | Resolution | Channels | Operation |
|---|---|---|---|---|
| 1 | Encoder | 572 → 568 | 1 → 64 | 2 × Conv3, ReLU |
| 2 | Encoder | 284 → 280 | 64 → 128 | MaxPool, 2 × Conv3 |
| 3 | Encoder | 140 → 136 | 128 → 256 | MaxPool, 2 × Conv3 |
| 4 | Encoder | 68 → 64 | 256 → 512 | MaxPool, 2 × Conv3 |
| 5 | Bottleneck | 32 → 28 | 512 → 1024 | MaxPool, 2 × Conv3 |
| 6 | Decoder | 56 (after concat) | 1024 → 512 | UpConv, concat, 2 × Conv3 |
| 7 | Decoder | 104 | 512 → 256 | UpConv, concat, 2 × Conv3 |
| 8 | Decoder | 200 | 256 → 128 | UpConv, concat, 2 × Conv3 |
| 9 | Decoder | 388 | 128 → 64 | UpConv, concat, 2 × Conv3 |
| Output | — | 388 | 64 → C | 1 × 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.
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.
- Backbone CNN + FPN (Feature Pyramid Network)
- RPN generates region proposals
- RoI Align (not RoI Pooling) extracts features — uses bilinear interpolation for sub-pixel precision
- Three parallel heads: classification, box regression, and mask prediction (small FCN per RoI)
9. Evaluation Metrics
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.
mIoU = (1/C) ∑c=1C IoUc
The standard metric for semantic 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 0 | Pred 1 | |
|---|---|---|
| True 0 | 800 (TN) | 50 (FP) |
| True 1 | 30 (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
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.