Module 9: Image Segmentation
1. Learning Objectives
- Understand the principles of semantic and instance segmentation
- Explore deep learning architectures used in segmentation tasks
- Apply pre-trained segmentation models on real images
2. What is Image Segmentation?
Image segmentation is the process of partitioning an image into meaningful segments or regions. Unlike object detection, segmentation assigns a label to each pixel.
Semantic vs. Instance Segmentation
- Semantic Segmentation: Classifies each pixel into a category (e.g., person, road).
- Instance Segmentation: Differentiates between individual objects of the same category (e.g., person 1, person 2).
3. Key Models and Architectures
- Fully Convolutional Networks (FCN): Pioneered semantic segmentation using CNNs
- U-Net: Widely used in medical imaging with encoder-decoder structure
- DeepLab v3+: Combines atrous convolutions and spatial pyramid pooling
- Mask R-CNN: Extends Faster R-CNN for instance segmentation
4. Applications
- Autonomous driving (lane and road detection)
- Medical image analysis (tumor segmentation)
- Remote sensing (land use classification)
- Interactive photo editing
5. Lab: Run Semantic Segmentation using DeepLabV3
from torchvision import models
import torchvision.transforms as T
from PIL import Image
import matplotlib.pyplot as plt
# Load a pretrained DeepLabV3 model
model = models.segmentation.deeplabv3_resnet101(pretrained=True).eval()
# Load and preprocess image
img = Image.open("your_image.jpg")
transform = T.Compose([T.Resize(520), T.ToTensor()])
input_tensor = transform(img).unsqueeze(0)
# Run inference
with torch.no_grad():
output = model(input_tensor)["out"][0]
segmentation = output.argmax(0)
# Display result
plt.imshow(segmentation)
plt.axis('off')
plt.show()
6. Assignment
Objective: Explore segmentation models and perform pixel-wise classification.
- 1. Run a semantic segmentation model (e.g., DeepLabV3) on an image of your choice
- 2. Save the segmented mask as an image
- 3. Compare the segmentation result with the original image
- 4. (Optional) Try instance segmentation using Mask R-CNN
Deliverables: Report, input/output images, segmentation mask
Due: End of Week 9