IT5409 Ch5 Segmentation v2
IT5409 Ch5 Segmentation v2
3
Introduction
• Purpose:
‒ to partition an image into meaningful regions with
respect to a particular application
• Goal:
‒ to cluster pixels into salient image regions, i.e., regions
corresponding to individual surfaces, objects, or natural
parts of objects.
• The segmentation is based on the feature
measurements taken from the image:
‒ grey level, color, texture, depth or motion…
4
Introduction
5
Introduction
• Entity can be extracted from images using mask
6
Applications
• Image segmentation
‒ is usually an initial and vital step in a series of processes
aimed at overall image understanding of computer vision
• Segmentation applications:
‒ Object recognition;
‒ Image retrieval;
‒ Medical image analysis;
‒ Boundary estimation within motion or stereo systems;
‒ Tracking of objects in a video;
‒ Classification of terrains visible in satellite images
‒…
8
Applications
9
Approaches for image segmentation
• Segmentation is usually based on:
‒ discontinuities: edges
• sudden changes, borders (frontiers) between regions…
‒ homogeneous zones: regions
• same color, texture, intensity, ...
10
Approaches for image segmentation
‒ Pixel-based approach
‒ Region-based approach:
• look for homogeneous areas in the image
‒ Edge-based approach :
• look for discontinuities in the image
• A closed edge is equivalent to a region
‒ Hybrid (Dual) approach (region + edge)
11
Examples
Original images Segmented images
12
Pixel-based approach
• Pixel-based approach
‒ Thresholding
‒ Clustering
13
Thresholding
• Thesholding is a simple and popular method for
object segmentation in digital images
• Thresholding can be
‒ Global: one threshold for the whole image
‒ Local: one threshold for a part of the image
‒ Adaptive: one threshold ajusted according to each
image or each image part
15
Basic global thresholding
• Basic thresholding (2 classes) – main idea :
‒ IF value(pixel) >= threshold THEN value(pixel) = 1 (or 255)
‒ IF value(pixel) < threshold THEN value(pixel) = 0
16
Example
17
Basic global thresholding
• Find the threshold on histogram of gray level
intensity (histogram thresholding)
0, 𝑓(𝑥, 𝑦) < 𝑇
𝑔 𝑥, 𝑦 = ቊ
1, 𝑓(𝑥, 𝑦) ≥ 𝑇
18
Basic global thresholding
• Threshold value: not difficile if
‒ Controled environment
‒ Industrial applications
19
Multi-thresholds
• n thresholds to split the image in n+1 classes:
‒ IF value(pixel) < threshold_1
• THEN value(pixel) = 0
‒ IF value(pixel) >= threshold_1 && value(pixel) <
threshold_2
• THEN value(pixel) = 1
‒…
‒ IF value(pixel) >= threshold_n
• THEN value(pixel) = n
• Problems: How many thresholds?
20
Multi-thresholds
0, 𝑓 𝑥, 𝑦 < 𝑇1
𝑔 𝑥, 𝑦 = ቐ1, 𝑇2 > 𝑓 𝑥, 𝑦 ≥ 𝑇1
2, 𝑓 𝑥, 𝑦 ≥ 𝑇2
21
Threshold value
• Global thresholding: How to find the value of the
threshold T ?
‒ Value obtained by tests
‒ The mean value of gray values
‒ The median value between the min gray level and the
max one
‒ One value balancing both sections of the histogram
• automatic thresholding
22
Choice of thresholds (optimal)
• 2 classes (background and object) in an image
‒ We suppose mathematical models for distributions
(gaussians, etc.)
‒ We determine the probability of error in the classes 1
and 2
‒ We search for a threshold T resulting in a minimum error
• Several methods for achieving this
Source : www.iro.umontreal.ca/~dift2730/
23
Example: Global automatic thresholding
• One possible algorithm:
‒ Choose an initial value for the threshold T (mean, median, …)
‒ We obtain 2 groups of pixels
• G1 where f(x,y) >= T and G2 where f(x,y) < T
‒ Compute the gray level means for G1 and G2 -> μ1 and μ2
‒ Compute a new value for T
• T = 1/2 (μ1 + μ2)
‒ Repeat until T is ~ constant
24
Example: Otsu algorithm
• Sweep all possible threshold value for T
• For each value of T:
‒ Compute the mean and variance for each
class
‒ We look for the intraclass variance
• Means: 𝜇1 , 𝜇2
• Variances: 𝜎12 , 𝜎22
• Inter-class variance:
𝜎𝑤2 = 𝑃1 ∗ 𝜎12 + 𝑃2 ∗ 𝜎22
26
Global threshold: problem
• Problem:
‒ Global thresholding cannot be used in that case
• Solution: adaptive local thresholding
27
Example of adaptive thresholding
• Split the image in sub-images and process each sub-image with its own
threshold
• The main decision is to choose the size of the sub-images
• Before processing each sub-image, check the variance to make sure that
the sub-image contains two regions, and not only one.
‒ Example: no thresholding for a sub-image if variance<100
28
Example of adaptive thresholding
Bimodal
Bimodal ?
29
Example of adaptive thresholding
30
Clustering-based segmentation
• Image is considered as a set of N image pixels.
• Attributes (property) of the pixels
‒ gray level of single-band gray tone images,
‒ color values of three-band color images: (r, g, b)
‒ values of multi-band images, …
• Based on the similar attribute, pixels classification operators
partition an image into homogeneous regions.
‒ Clustering provides a grouping of the pixels that is dependent on
their values in the image but not necessarily on their locations in the
image unless location is a specified property
‒ Classifier provide the pixel classes which should be homogeneous
regions.
31
Clustering algorithms
• Image segmentation approaches including:
‒ Feature space clustering approaches
‒ Graph-based approaches
• Clustering algorithms:
‒ K-Means clustering
‒ Mean-Shift Clustering
‒ Expectation-Maximization Clustering
‒ Watershed Segmentation
‒ Graph Cuts (Spectral clustering)
‒ Normalized cuts
‒…
32
K-means clustering
33
Slide based on one by Eamonn Keogh
4
k1
3
2
k2
k3
0
0 1 2 3 4 5
4
k1
3
2
k2
k3
0
0 1 2 3 4 5
4
k1
k3
1 k2
0
0 1 2 3 4 5
4
k1
k3
1 k2
0
0 1 2 3 4 5
k2
1 k3
0
0 1 2 3 4 5
expression in condition 1
Slide based on one by Eamonn Keogh
K-means Clustering: examples
Source : D.A. Forsyth and J. Ponce. Computer Vision : A Modern Approach. Prentice-Hall, 2002.
40
K-means clustering: examples
41
Example
42
Pixel-based approach: Pros & cons
• Pros
‒ Simple, fast
43
Features for segmentation
• Intensity, Color?
• Position
• Texture
•…
44
Segmentation as clustering
Depending on what we choose as the feature space, we
can group pixels in different ways.
F2
Filter bank
of 24 filters
…
F24
Feature space: filter bank responses (e.g., 24-d)
Slide credit: Kristen Grauman
Segmentation with texture features
• Find “textons” by clustering vectors of filter bank outputs
• Describe texture in a window based on texton histogram
Count
Image Texton map
Texton index
Count
Count
Texton index Texton index
Malik, Belongie, Leung and Shi. IJCV 2001. Adapted from Lana Lazebnik
Image segmentation example
50
Region-based segmentation
• Region-based approaches provide :
‒ All pixels must be assigned to regions
‒ Each pixel must belong to a single region only
‒ Each region must be uniform
‒ Any merged pair of adjacent regions must be non-
uniform
‒ Each region must be a connected set of pixels
• Region-based approaches:
‒ Different methods
‒ Common point: homogeneity criteria
51
Region growing
• Start from a point (seed) and add neighbor pixels
following a given criteria
• The seeds can be manually or automatically chosen
‒ automatic seeds in very homogeneous zones for example
52
Region growing algorithm
• Algorithm:
‒ Choose K random pixels in K regions
‒ Use 8-connected and threshold to determine
‒ Repeat a and b until almost points are K classified.
• Example illustrated:
53
Region growing with multi-seeds
54
Example
Simulation
of region
growing
(90% pixels )
55
Split-and-merge
• Split (step 1)
‒ Recursively split all non-homogeneous
regions following a given criteria
• variance, max-min, …
‒ Dividing one region gives 4 subregions
‒ Subregion attributes are re-computed
• Merge (step 2)
‒ Group all homogeneous adjacent
regions following a given criteria
56
Split-and-merge: split
Image initiale
Split1
Split 2
split 3
Quadtree
58
Split-and-merge
59
Edge-based segmentation
• Finding region based on edges
• Algorithms:
‒ Basic Edge Detection
‒ The Marr-Hildreth edge detector (LoG)
‒ Short response Hilbert transform (SRHLT)
‒ Watersheds
60
Watershed segmentation
• We consider the image as a 3D shape using the
gray level as the third dimension
2D image Visualization in 3D
Source : http://www.gpa.etsmtl.ca/cours/gpa669/
61
Watershed segmentation
• After we reverse (upside down) the values to
create « holes » in the shape
62
Watershed segmentation
• Next we fill in the holes with water
63
Watershed segmentation
64
Watershed segmentation
https://docs.opencv.org/master/d3/db4/tutorial_py_watershed.html
65
Watershed segmentation
66
Segmentation – advices
• Image segmentation
‒ No method works for all images
‒ No miracle, no warranty!
67
Segmentation – advices
• Image Pre-processing:
‒ good selection of sensors and energy source, and
controled image acquisition conditions help to make
segmentation easier and more efficient
• For some applications, we realize today that we
can avoid to segment the image. It is often better
like this.
68
Limits of segmentation
69
Segmentation vs. grouping
• Term 'segmentation' :
‒ less used
‒ segmentation, which let think
about an exact image splitting
into regions
• 'Pixel grouping'
‒ which refers only to a notion
of similarity between pixels
without relation on the
content of regions.
70
Motion segmentation
76