Image Segmentation - Pixel-Level Classification and Understanding
Image segmentation takes classification to a granular level: instead of labeling entire images or detecting objects, it classifies every pixel. This enables detailed understanding of image content and is crucial for many applications.
Segmentation Types
Semantic Segmentation
Task: Classify each pixel into category
Output: Pixel-level class map
Original: [Image with road, cars, trees]
Output: [Each pixel labeled: road/car/tree/sky]
Visualization (colors represent classes):
Red: Cars
Blue: Road
Green: Trees
Sky: White
Characteristic:
- All objects of same class: One label
- Example: Three dogs → all labeled “dog”
Applications:
- Autonomous driving (road/sidewalk/vegetation)
- Medical imaging (tumor/healthy tissue)
- Satellite imagery (land use/water bodies)
Instance Segmentation
Task: Segment individual object instances
Output: Separate mask per object
Original: [Image with 3 dogs]
Output: [Dog 1 mask, Dog 2 mask, Dog 3 mask]
Characteristic:
- Each object gets unique label
- Enables counting and individual analysis
Applications:
- Crowd counting
- Individual animal tracking
- Surgical planning (identify specific organs)
Panoptic Segmentation
Task: Combine semantic and instance segmentation
Output: All things (objects) with instances, stuff (background) semantically
Output:
- Car 1 (instance)
- Car 2 (instance)
- Road (semantic)
- Sky (semantic)
Key Architectures
FCN (Fully Convolutional Networks)
Innovation: End-to-end, pixel-to-pixel network
Architecture:
Input Image
↓
Convolutional layers (encode)
↓
Deconvolutional layers (decode)
↓
Output: Per-pixel predictions
Process:
- Encoder: Downsampling (reduce spatial dimension, increase semantic meaning)
- Decoder: Upsampling (recover spatial resolution)
- Skip connections: Preserve low-level details
Limitations:
- Upsampling loses detail
- Coarse boundaries
U-Net
Innovation: Symmetric encoder-decoder with skip connections
Architecture:
Output
↑
Deconvolutional Block
↙ ↖
Skip from Decoder
Encoder Upsampling
↓ ↑
Encoder Block → Bottleneck
↓
Downsampling
Input
Key Features:
- Symmetric: Encoder mirrors decoder
- Skip connections: All encoder levels connected to decoder
- Preserves spatial information
Advantages:
- Sharp boundaries
- Works with limited data
- Efficient
Originally for: Medical image segmentation
Current: General purpose segmentation
DeepLab
Innovation: Atrous (dilated) convolution for receptive field control
Atrous Convolution:
Standard Conv: Atrous Conv (dilation=2):
[•] [•]•[•]
Dilation increases receptive field without downsampling
Components:
- Atrous spatial pyramid pooling (ASPP)
- Multiple dilation rates
- Better context understanding
Versions:
- DeepLabv3: Multi-scale context
- DeepLabv3+: Encoder-decoder structure
Mask R-CNN
Extend Faster R-CNN with segmentation masks.
Pipeline:
- Detect object (bounding box)
- Segment individual instance (mask)
- Per-object prediction
Advantage: Instance segmentation with detection
Training Segmentation Models
Loss Functions
Pixel-Level Classification:
- Each pixel: Independent classification problem
- Cross-entropy loss for each pixel
- Average across all pixels
Common Loss:
loss = CrossEntropyLoss(predictions, targets)
# Average over all pixels
Class Imbalance:
Problem: Many pixels are background, few are objects
Solutions:
- Weighted cross-entropy
- Focal loss
- Dice loss: Focus on overlap with target
Dice Loss:
Dice = 2 * |Prediction ∩ Target| / |Prediction| + |Target|
Loss = 1 - Dice
Data Augmentation
Geometric:
- Rotation
- Flipping
- Elastic deformations
Intensity:
- Brightness, contrast
- Color jittering
- Blur, noise
Important: Augmentations applied identically to image and mask
Class Balancing
Solutions for imbalanced data:
- Weighted Loss: Penalize rare classes more
- Oversampling: Include rare classes more often
- Undersampling: Reduce common classes
- Synthetic Data: Generate missing classes
Evaluation Metrics
Pixel Accuracy
Accuracy = Correct Pixels / Total Pixels
Problem: Dominated by background
Mean IoU (Intersection over Union)
IoU (per class) = Intersection / Union
mIoU = Average IoU across all classes
Better: Accounts for all classes equally
Example:
Class 1 (car): IoU = 0.8
Class 2 (road): IoU = 0.9
Class 3 (sky): IoU = 0.85
mIoU = (0.8 + 0.9 + 0.85) / 3 = 0.85
Dice Coefficient
Dice = 2 * |Prediction ∩ Target| / |Prediction| + |Target|
Similar to IoU, sometimes used interchangeably
Practical Considerations
Memory Efficiency
Full resolution segmentation is memory-intensive:
Solutions:
- Process at lower resolution
- Patch-based processing (process image in tiles)
- Dilated convolutions (larger receptive field without downsampling)
- Efficient architectures (MobileNet backbone)
Real-Time Segmentation
Challenges:
- Full resolution processing slow
- Cannot skip frames in video
Solutions:
- Lighter architectures
- Lower resolution
- GPU acceleration
- Quantization
Semi-Supervised Learning
Limited labeled data:
- Self-training: Use predictions on unlabeled data
- Consistency regularization: Consistency under perturbations
- Pseudo-labeling: Generate labels automatically
Benefit: Leverage abundant unlabeled data
Applications in Detail
Autonomous Driving
Task: Understand road scene at pixel level
Classes:
- Road (drivable)
- Sidewalk
- Vehicles
- Pedestrians
- Vegetation
- Sky
- Buildings
Benefit: Precise understanding for safe navigation
Challenges:
- Real-time performance
- All weather/lighting
- Safety critical
Medical Image Analysis
Example: Tumor Segmentation
Input: CT or MRI scan
Output: Tumor region identified
Benefits:
- Volume calculation
- Surgical planning
- Treatment monitoring
- Automated screening
Challenges:
- Limited training data
- Variability across patients
- Regulatory requirements
Video Instance Segmentation
Extension: Segment objects consistently across frames
Challenges:
- Temporal consistency
- Occlusion handling
- Real-time performance
Satellite Imagery
Applications:
- Land use classification
- Urban planning
- Disaster assessment
- Crop monitoring
Challenges:
- High resolution imagery
- Seasonal variations
- Class imbalance
Advanced Techniques
3D Segmentation
Extend to volumetric data:
Input: 3D volume (CT, MRI)
3D Convolution: Process volume directly
Output: 3D segmentation mask
Challenges: Memory, computation
Video Segmentation
Temporal consistency:
- Propagate segmentations across frames
- Optical flow guidance
- Recurrent networks
Few-Shot Segmentation
Learn to segment new classes with few examples:
Support: Few examples of new class
Query: Image to segment
Output: Segmentation of new class
Tools and Frameworks
PyTorch Segmentation Models
Pre-trained models:
- U-Net
- DeepLab
- PSPNet
- Segmentation Models library
TensorFlow
- DeepLabv3+
- U-Net implementations
- Pre-trained checkpoints
Cloud APIs
AWS, Google Cloud, Azure:
- Semantic segmentation services
- Instance segmentation
- Custom training
Conclusion
Image segmentation achieves pixel-level understanding of images. Semantic segmentation classifies all pixels; instance segmentation separates objects. Modern architectures like U-Net and DeepLab balance accuracy and efficiency. Understanding loss functions, metrics, and training strategies enables building effective segmentation systems. From autonomous driving to medical imaging, segmentation enables detailed visual understanding critical for many applications. As resolution and model sophistication increase, segmentation continues expanding into new domains and challenges.