Topic2 Semantic Image Segmentation
Topic2 Semantic Image Segmentation
Perfectly segmented
Not segmented
Partially segmented
Source: https://www.mathworks.com/discovery/image-segmentation.html
Terminology
Terminology
1. Image segmentation:
process of automatically labeling each pixel in an image as
belonging to foreground or background.
2. Semantic segmentation:
connected labeled pixels map to object classes.
3. Instance segmentation:
connected labeled pixels correspond to individual instances of
a class.
Terminology
Image segmentation: foreground (color-coded in red) vs. background.
Source: https://www.mathworks.com/discovery/image-segmentation.html
Terminology
Semantic segmentation: different classes are labeled
differently (car=purple, truck=light blue, bus = pink, etc.).
Source: https://deepdrive.pl/datasets/
Terminology
Instance segmentation: individual instances of a class (in this
case, car) are labeled differently.
Source: https://deepdrive.pl/bdd100k-dataset/
Figures of merit
Evaluating Segmentation Accuracy
Steps:
1. Choose figure of merit
• Jaccard
• Dice
• BF score
2. Select ground truth (mask)
3. Compute figure of merit (see MATLAB functions on next slide)
• A value of 1 is ideal (perfect match, pixel by pixel)
Evaluating segmentation accuracy
Source: Marques (2011) “Practical Image and Video Processing Using MATLAB”, Wiley.
• There is no universally accepted taxonomy for classification of
image segmentation algorithms.
Source: Marques (2011) “Practical Image and Video Processing Using MATLAB”, Wiley.
Threshold-based techniques: variants
• Variants
• Global thresholding (graythresh, otsuthresh)
• Computes a single value of T for the whole image using Otsu’s method, which chooses a
threshold that minimizes the intraclass variance of the thresholded black and white
pixels. The resulting value can be used to binarize the image using imbinarize.
Different values
of T lead to
different results
T = 0.25
Source: Marques (2011) “Practical Image and Video Processing Using MATLAB”, Wiley.
Threshold-based techniques: examples
Global thresholding
is sensitive to uneven
illumination
Source: Marques (2011) “Practical Image and Video Processing Using MATLAB”, Wiley.
Threshold-based techniques: examples
Global thresholding
is sensitive to noise
Source: Marques (2011) “Practical Image and Video Processing Using MATLAB”, Wiley.
Segmentation: Region growing techniques
• Region growing is a simple pixel-based image segmentation method that starts from a
pixel location (the seed) and grows a region around it according to certain criteria.
• Essentially, “keep growing until the pixels within the connected region are similar to each other and
all the surrounding pixels are sufficiently different – according to some definition of similarity”.
• gradientweight, graydiffweight : auxiliary functions to compute weights for image pixels based
on image gradient (i.e., grayscale intensity difference)
Source: https://www.mathworks.com/discovery/image-segmentation.html
Segmentation: Active contours (snakes)
• Iterative region-growing image segmentation algorithm.
• Using the active contour algorithm, you specify initial curves on an image and
then use the activecontour function to evolve the curves towards object
boundaries.
Source: https://www.mathworks.com/help/images/ref/activecontour.html
Segmentation: clustering-based techniques
• Basic idea: treat segmentation as a clustering problem, in which pixels with
similar intensity levels are labeled as belonging to the same cluster.
• Popular algorithm: k-means clustering.
• In MATLAB: imsegkmeans (2D images) and imsegkmeans3 (3D volumes)
Source: https://www.mathworks.com/discovery/image-segmentation.html
Segmentation: morphological techniques
• Uses the watershed transform, which finds "catchment basins" or "watershed ridge lines" in
an image by treating it as a surface where light pixels represent high elevations and dark pixels
represent low elevations.
• The watershed transform can be used to segment contiguous regions of interest into distinct
objects.
• In MATLAB: watershed
Source: https://www.mathworks.com/help/images/ref/watershed.html
Segmentation: superpixel techniques
• Basic idea: group pixels into regions
with similar values.
• Using these regions in image
processing operations, such as
segmentation, can reduce the
complexity of these operations.
simple linear iterative clustering
(SLIC) algorithm.
• In MATLAB:
superpixels (2D images) and
superpixels3 (3D volumes)
Source: https://www.mathworks.com/help/images/ref/superpixels.html
Segmentation: graph-based techniques
• Basic idea:
treat segmentation as a
graph cut problem, in
which pixels are the graph
nodes and pixel similarity is
treated as the edges
connecting the nodes.
Source: https://www.cis.upenn.edu/~jshi/GraphTutorial/Tutorial-ImageSegmentationGraph-cut1-Shi.pdf
Segmentation: graph-based techniques
• In MATLAB: lazysnapping
Source: https://www.mathworks.com/help/images/ref/lazysnapping.html
Image segmentation
apps in MATLAB
Image Segmentation with MATLAB: beyond
library function calls
MATLAB has interactive GUI-based apps for:
Source: https://www.mathworks.com/discovery/image-segmentation.html
Image Segmenter App
Interactive app that lets you try several methods to create segmentation masks, using automatic algorithms (e.g.,
flood fill), semi-automatic techniques (e.g., graph cut), and manual techniques (e.g., drawing ROIs). You can also
refine masks using morphology or an iterative approach such as active contours (snakes).
Resulting masks (and the code used to create them) can be exported to the workspace.
• Features:
• Object segmentation
• Recognition in context
• Superpixel stuff segmentation
Microsoft • 330K images (>200K labeled)
• 1.5 million object instances
Objects in • https://cocodataset.org/
Context)
Semantic image
segmentation using
deep learning in
MATLAB
Semantic Image Segmentation using Deep Learning in MATLAB
Basic steps:
1. Label training images with Image Labeler app (or search Web for labeled data)
2. Create two datastores
• ImageDatastore
• PixelLabelDatastore
3. Partition datastores into training and test sets
4. Import a pretrained CNN model and modify it to become an encoder-decoder
network (or create your own network from scratch)
5. Train and evaluate your network.
Source: https://www.mathworks.com/videos/semantic-segmentation-overview-1510858047780.html
Semantic Image Segmentation using Deep Learning in MATLAB
Step 1: Label your data
• Prepare a list of labels that will be used to label selected regions of interest
(ROIs) within each image.
Semantic Image Segmentation using Deep Learning in MATLAB
Step 1: Label your data (cont’d)
• Use MATLAB Image Labeler app to generate pixel-level masks for the regions of
interest (ROIs)
Source: https://github.com/divamgupta/image-segmentation-keras
Sidenote: CNNs, encoder-decoder, and transfer learning
• Traditional CNN
Sidenote: CNNs, encoder-decoder, and transfer learning
• Encoder-decoder architecture
Source: https://www.semanticscholar.org/paper/SSeg-LSTM%3A-Semantic-Scene-Segmentation-for-Syed-Morris/b5e4abb8c1bebf7d531202e57e431c638dd1c4af
Sidenote: CNNs, encoder-decoder, and transfer learning
Source: https://www.groundai.com/project/fastventricle-cardiac-segmentation-with-enet/
Sidenote: CNNs, encoder-decoder, and transfer learning
• Transfer Learning
Source: https://divamgupta.com/image-segmentation/2019/06/06/deep-learning-semantic-segmentation-keras.html
Semantic Image Segmentation using Deep Learning in MATLAB
Key MATLAB functions:
• semanticseg
Takes an image and a pretrained network as input and returns semantic
segmentation of the input image.
• evaluateSemanticSegmentation
Evaluates semantic segmentation data set against ground truth.
Hands on!
MATLAB Assignment:
Semantic image segmentation using deep learning (semantic_segmentation_dl.mlx)
MATLAB Assignment:
Semantic image segmentation using deep learning (semantic_segmentation_dl.mlx)
• Part 1:
• Basic workflow for semantic image segmentation using a convolution-
deconvolution neural network created by you and trained from scratch.
• Segmentation metrics: global accuracy, class accuracy, IoU, weighted IoU, and
BF score.
• Part 2:
• Workflow for semantic image segmentation using a pretrained network and a
realistic public dataset (CamVid).
• Data augmentation.