Sub topic 1
What Image Segmentation Is and Why It Matters
Prerequisites
This chapter assumes you know basic Python and NumPy, and that you have seen image classification with convolutional neural networks. Knowing what a bounding box and a confidence score are will help in the later sections.
Representing segmentation: label maps and mask stacks
Image segmentation assigns a label to every pixel in an image. The result is stored in one of two common forms. A label map is a 2D integer array with the same height and width as the image, where each value is a class ID. A mask stack is a boolean array of shape (N, H, W), with one binary mask per object or class.
import numpy as np
label_map = np.array([[0, 0, 1],
[0, 2, 1]])
mask_stack = np.stack([label_map == c for c in (0, 1, 2)])
print(mask_stack.shape) # (3, 2, 3)Things versus stuff
Classes fall into two groups. Things are countable objects with clear boundaries, such as people, cars, or cups. Stuff is amorphous material without distinct instances, such as sky, grass, or road. This split matters because panoptic segmentation treats the two groups differently.
Semantic segmentation: one class per pixel
Semantic segmentation predicts a class for each pixel. Two cars side by side receive the same label, so the output does not show where one car ends and the next begins. It suits tasks like road scene understanding, where you care about which pixels are drivable.
Instance segmentation: separating individual objects
Instance segmentation finds each object and returns its own mask, along with a class and a confidence score. Two cars produce two separate masks, which makes it useful for counting or tracking objects. It usually applies to things only, because stuff regions rarely have clear instance boundaries.
Exercise
Why can semantic segmentation not separate two touching cars?
Show answer
It assigns one class to each pixel, so both cars share the same label and the output has no instance IDs.