Chapter 6. Image Segmentation
Chapter 6. Image Segmentation
Hà Nội, 2021 1
Chapter 6. Image Segmentation
1. Fundamentals
2. Point, Line, and Edge Detection
3. Thresholding
4. Image Segmentation Using Deep Learning
➢ Let R represent the entire spatial region occupied by an image. We may view
image segmentation as a process that partitions R into n subregions, R1, R2, …,
Rn, such that:
where Q(Rk) is a logical predicate defined over the points in set Rk and is the null
set.
➢ Two regions Ri and Rj are said to be adjacent if their union forms a connected
set.
➢ The regions are said to disjoint If the set formed by the union of two regions is
not connected.
➢ The fundamental problem in segmentation is to partition an image into regions
that satisfy the preceding conditions.
➢ Segmentation algorithms for monochrome images generally are based on one
of two basic categories dealing with properties of intensity values: discontinuity
and similarity.
▪ Edge-based segmentation
▪ Region-base segmentation
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 4
1. Fundamentals
(a) Image of a constant intensity region. (b) Boundary based on intensity discontinuities. (c) Result of
segmentation. (d) Image of a texture region. (e) Result of intensity discontinuity computations (note
the large number of small edges). (f) Result of segmentation based on region properties.
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 5
1. Fundamentals
6
Chapter 6. Image Segmentation
1. Fundamentals
2. Point, Line, and Edge Detection
3. Thresholding
4. Image Segmentation Using Deep Learning
➢ A line:
▪ a (typically) thin edge segment
▪ the intensity of the background on either side of the line is either much higher
or much lower than the intensity of the line pixels.
▪ “roof edges”
➢ Isolated point: a foreground (background) pixel surrounded by background
(foreground) pixels.
❖ Background
➢ an approximation to the first-order derivative at an arbitrary point x of a one-
dimensional function f(x)
❖ Background
➢ an approximation to the first-order derivative at an arbitrary point x of a one-
dimensional function f(x)
❖ Background
➢ The forward difference
❖ Background
➢ The central difference
❖ Background
❖ Background
➢ For two variables
❖ Background
❖ Background
➢ Spatial filter kernel
➢ Detected points
(a) Laplacian kernel used for point detection. (b) X-ray image of a turbine blade with a porosity manifested
by a single black pixel. (c) Result of convolving the kernel with the image. (d) Result of using Eq. (10-15)
was a single point (shown enlarged at the tip of the arrow).
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 19
2. Point, Line, and Edge Detection
❖ Line Detection
➢ EXAMPLE: Using the Laplacian for line detection.
(a) Original image. (b) Laplacian image; the magnified section shows the positive/negative double-line effect
characteristic of the Laplacian. (c) Absolute value of the Laplacian. (d) Positive values of the Laplacian.
❖ Line Detection
➢ EXAMPLE: Detecting lines in specified directions.
Line detection kernels. Detection angles are with respect to the axis system in above figure,
with positive angles measured counterclockwise with respect to the (vertical) x-axis.
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 21
2. Point, Line, and Edge Detection
❖ Line Detection
➢ EXAMPLE: Detecting lines in specified directions.
❖ Edge Models
➢ A step edge ➢ A ramp edge ➢ A roof edge
❖ Edge Models
❖ Edge Models
➢ EXAMPLE: Behavior of the first and second derivatives in the region of a noisy
edge.
➢ EXAMPLE: Behavior of the first and second derivatives in the region of a noisy
edge.
❖ Edge Detection
➢ The three steps performed typically for edge detection are:
▪ Image smoothing for noise reduction.
▪ Detection of edge points.
▪ Edge localization.
Magnitude:
Using the gradient to determine edge strength and direction at a point. Note that the edge
direction is perpendicular to the direction of the gradient vector at the point where the
gradient is computed. Each square represents one pixel.
Kirsch compass kernels. The edge direction of strongest response of each kernel is labeled below it.
The Sobel absolute value response of the two components of the gradient
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 34
2. Point, Line, and Edge Detection
The original image smoothed using a 5x5 averaging kernel prior to edge detection.
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 36
2. Point, Line, and Edge Detection
Diagonal edge detection. (a) Result of using the Kirsch kernel in Fig. 10.15(c) . (b)
Result of using the kernel in Fig. 10.15(d) . The input image in both cases was Fig.
10.18(a) .
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 37
2. Point, Line, and Edge Detection
(a) Result of thresholding Fig. 10.16(d) , the gradient of the original image.
(b) Result of thresholding Fig. 10.18(d) , the gradient of the smoothed image.
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 38
2. Point, Line, and Edge Detection
▪ convolving f and G:
(a) Two possible orientations (b) Range of values (shaded) of (c) The angle ranges of the edge
of a horizontal edge (shaded) , the direction angle of the edge normals for the four types of edge
in a 3x3 neighborhood. normal for a horizontal edge. directions in a 3x3 neighborhood.
r = αb + (1−α)a
1. Fundamentals
2. Point, Line, and Edge Detection
3. Thresholding
4. Image Segmentation Using Deep Learning
Single thresholding
Multiple thresholding
Intensity histograms that can be partitioned (a) by a single threshold, and (b) by dual thresholds.
▪ Segment the image using T in Eq. (1). This will produce two groups of pixels: G1, consisting of
pixels with intensity values > T and G2, consisting of pixels with values T.
▪ Compute the average (mean) intensity values m1 and m2 for the pixels in G1 and G2
respectively.
▪ Repeat Steps 2 through 4 until the difference between values of T in successive iterations is
smaller than a predefined value, T
(a) Noisy fingerprint. (b) Histogram. (c) Segmented result using a global
threshold (thin image border added for clarity).
Rafael C. Gonzalez, Richard E. Woods, “Digital image processing,” Pearson (2018). 57
3. Thresholding
(a) Image of an iceberg. (b) Histogram. (c) Image segmented into three regions
using dual Otsu thresholds.
1. Fundamentals
2. Point, Line, and Edge Detection
3. Thresholding
4. Image Segmentation Using Deep Learning
66
A Gentle Introduction to Image Segmentation for Machine Learning (v7labs.com)
4. Image Segmentation Using Deep Learning
67
A Gentle Introduction to Image Segmentation for Machine Learning (v7labs.com)
4. Image Segmentation Using Deep Learning
68
A Gentle Introduction to Image Segmentation for Machine Learning (v7labs.com)
4. Image Segmentation Using Deep Learning
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 69
4. Image Segmentation Using Deep Learning
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 70
4. Image Segmentation Using Deep Learning
Encoder-Decoder architecture
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 72
4. Image Segmentation Using Deep Learning
❖ Skip connections
❖ Transfer learning
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 74
4. Image Segmentation Using Deep Learning
❖ Loss function
➢ Each pixel of the output of the network is compared with the corresponding pixel
in the ground truth segmentation image. We apply standard cross-entropy loss
on each pixel.
In binary classification, where the number of classes M equals
2, cross-entropy can be calculated as:
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 75
4. Image Segmentation Using Deep Learning
❖ Implementation
➢ Dataset: The first step in training our segmentation model is to prepare the
dataset.
➢ Data augmentation:
❖ Implementation
➢ Building the model: define our segmentation model with skip connections
➢ Choosing the model:
▪ Choosing the base model: select an appropriate base network → ResNet, VGG-
16, MobileNet, Custom CNN, …
▪ Select the segmentation architecture: FCN, SegNet, UNet, PSPNet, …
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 77
4. Image Segmentation Using Deep Learning
❖ Implementation
Architecture of FCN32
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 78
4. Image Segmentation Using Deep Learning
❖ Implementation
Architecture of SegNet
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 79
4. Image Segmentation Using Deep Learning
❖ Implementation
Architecture of UNet
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 80
4. Image Segmentation Using Deep Learning
❖ Implementation
Architecture of PSPNet
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 81
4. Image Segmentation Using Deep Learning
❖ Implementation
➢ Choosing the input size: If there are a large number of objects in the image, the
input size shall be larger. The standard input size is somewhere from 200x200
to 600x600.
➢ Training: output are the model weights
➢ Testing: get predictions from a saved model
A Beginner's guide to Deep Learning based Semantic Segmentation using Keras | Divam Gupta 82
4. Image Segmentation Using Deep Learning
❖ Implementation
83