Lecture 8 Image - Segmentation Updated
Lecture 8 Image - Segmentation Updated
Objectives
3
Outline
4
Edge Detection
• Convert a 2D image into a set of curves
●Extracts salient features of the scene
●More compact than pixels
5
Edges
• Edges are caused by a variety of factors
surface normal
discontinuity
depth
discontinuity
surface color
discontinuity
illumination
discontinuity
6
Edges
• Edge is Where Change Occurs
• Change is measured by derivative in 1D
• Biggest change, derivative has maximum magnitude
• Or 2nd derivative is zero.
7
Image Gradient
• The gradient of an image:
• The gradient points in the direction of most rapid change
in intensity
8
Image Gradient
• gradient direction
9
Types of Edges
10
Point, Line and Edge Detection
11
Point, Line and Edge Detection
Background
2 f
f (x 1) f (x 1) 2 f (x)
x 2
• In 2-D:
- Filtering with a mask (e.g. Sobel, Laplacian)
12
Point, Line and Edge Detection
Background
Intensity profile
along the line
13
Point, Line and Edge Detection
Background
14
Point, Line and Edge Detection
Point Detection
• The Laplacian
2
f 2
f
2 f (x, y) 2 2
x y
1 if | R(x, y) | T 9
R wk z k
g(x, y)
0 otherwise k 1
T: threshold
15
Point, Line and Edge Detection
Point Detection
Point Detection
Mask(Laplacian)
Showing single
point using
شفرة التوربينات ذات المسامية a threshold
contains a single black
technique
pixel
• Second derivatives:
- Stronger response and thinner lines (than first derivatives)
- Double-line effect (must be handled properly)
Laplacian of image
17
Point, Line and Edge Detection
Line Detection
• First Derivatives:
- Use line detection masks
18
Point, Line and Edge Detection
Line Detection
• First Derivatives:
قالب Mask 1 st
السندات derivative
السلكية of image
Zoomed
view of
Zoomed view of the
the top left region bottom
Right
region
ALL
Point
Satisfied
The image in (b) with all The
Negative values set to condition
zero Of (e)
Points
enlarged 19
Point, Line and Edge Detection
Edge Models
• Edge models
• Edges vs Boundaries
- Edge: local
- Boundary: global (encompasses a region)
- Edges often must be “linked” to form a boundary
20
Point, Line and Edge Detection
Edge Models
2 pixels
9 pixels 3 pixels
21
Point, Line and Edge Detection
Edge Models
• Properties of derivatives:
- 1st Derivative
• Detect using threshold
• Thick
- 2nd Derivative
• Two values for edge
• Detect zero-crossing
• Result is thinner
22
Point, Line and Edge Detection
Edge Models
• Noise sensitivity:
- Derivative increasingly sensitive to noise with order derivative
- 1st derivative (gradient) better than 2nd derivative for noisy images
23
Point, Line and Edge Detection
Edge Detection
- Magnitude
M (x, y) mag(f ) g x g y 2 2
f f
approximation: mag(f ) +
x y
- Direction
gx
(x, y) tan 1
g
y
- Direction of the edge
- 90∘
24
Point, Line and Edge Detection
Edge Detection
25
Point, Line and Edge Detection
Edge Detection
f
f (x, y 1) f (x, y)
y
- Gradient operators (filters)
• Example (Sobel)
27
Point, Line and Edge Detection
Edge Detection
28
Point, Line and Edge Detection
Edge Detection
29
Point, Line and Edge Detection
Edge Detection
• Example: thresholding
30
Point, Line and Edge Detection
Edge Detection
- Laplacian of Gaussian
2 G(x, y) 2 G(x, y)
G(x, y)
2
x 2
y2
x 2 2 y 2 2
x2 y 2 x2 y 2
2e 2 e
x y
x y 2 2
x y 2 2
x2 1 2 2 y 2 1 2 2
4 2 e 4 2 e
x2 y 2
x y
2 2 2
2 G(x, y) e
2 2
4
31
Point, Line and Edge Detection
Edge Detection
32
Point, Line and Edge Detection
Edge Detection
33
Point, Line and Edge Detection
Edge Detection
34
Point, Line and Edge Detection
Edge & Boundary Detection
- Direction of Gradient
35
Point, Line and Edge Detection
Edge & Boundary Detection
36
Point, Line and Edge Detection
Canny Edge Detector
• Goals
- Good detection: locate and mark all real edges
- Good localization: edges as close as possible to true edge
- Clear response: only one response per edge
• Stages
37
Point, Line and Edge Detection
Canny Edge Detector
• Nonmaxima suppression
- Possible directions: d1: horizontal, d2 : -45, d3 : vertical, d4 : +45
Example of
“horizontal” edge
1. If TL < M(x, y) < TH: accept as part of the boundary only if it is connected
to a strong pixel (e.g. 8-connectivity).
→ This is a “weak” pixel
40
Point, Line and Edge Detection
Canny Edge Detector
41
Outline
42
Hough Transform هاف ترنسفورم
Hough Transform
هاف ترنسفورم
• Objective: detect lines
(xi , yi ) b yi axi
x
a
Infinite lines through point (xi, yi) Single line for point (xi, yi)
Each line has a different a, b Infinitely many (a, b) along the line
46
Hough Transform
- The (unique) intersection (in parameter space) defines the parameters (a’, b’)
of the line
• Parameter space for all lines passing through (xi, yi), (xj, yj)
Intersection (ρ’, θ’) corresponds to
line passing through both (xi, yi)
and (xj, yj)
48
Hough Transform
49
These lines
Not exist in the
Hough Transform
Image , we
Set these lines
To imagine that
• Example These point align
θj
50
Hough Transform
• Example
Edge
detection
Hough
transform Detected
(strong
accumulations
lines
indicate lines)
51
Hough Transform
52
Hough Transform
Other Curves
53
Outline
54
Thresholding
• Simple thresholds:
- Two-level threshold
- Three-level threshold
55
Thresholding
Role of Noise
56
Thresholding
Role of Illumination
57
Thresholding
Basic Global Thresholding
• Algorithm
- Guess an initial threshold T
(e.g. image mean)
- Segment using T
- Calculate a mean for each region:
m 1, m 2
- Update T:
m m2
T 1
2
- Repeat until change in T < T0
58
Thresholding
Optimum Global Thresholding: Otsu’s Method
Procedure
1. Normalized histogram:
ni L: intensity levels
pi MxN: image size
MN ni: pixels with intensity i
2. Cumulative sums
59
Thresholding
Optimum Global Thresholding: Otsu’s Method
Procedure
3. Cumulative means
k
1 k
- Mean intensity of pixels in class C1: m1 (k ) iP(i | C1 ) ipi
i0 P1 (k ) i0
L1
1 L1
- Mean intensity of pixels in class C2: m2 (k ) iP(i | C2 ) ipi
ik 1 P2 (k ) ik 1
m P
2 G 1
m 2
where
k
m(k ) ipi
B
P1 (1 P1 ) i0
60
Thresholding
Optimum Global Thresholding: Otsu’s Method
Procedure
6. Otsu’s threshold
- It is the value k* that maximizes between-class variance
B2 (k*) max B2 (k )
0k L1
- How? Evaluate for all integer values of k and choose the “best” one
- Threshold with k*
1, if f (x, y) k *
g(x, y)
0, if f (x, y) k *
7. Evaluate the separability measure
B2
2 𝜎𝐺2 : Global variance (all the image)
G
61
Thresholding
Optimum Global Thresholding: Otsu’s Method
• Example:
62
Thresholding
Image Smoothing to Improve Global Thresholding
63
Thresholding
Edge Information to Improve Global Thresholding
• Procedure:
- Compute edges (magnitude of gradient or absolute value of Laplacian)
- Generate a “mask thresholding the edges (e.g. using high 90s percentile)
- Use the mask to select regions in the original image, then threshold the image
64
Thresholding
Edge Information to Improve Global Thresholding
65
Thresholding
Multiple Thresholds
where Pk pi and mk
1
Pk
ip i
iCk iCk
66
Thresholding
Multiple Thresholds
67
Thresholding
Variable Thresholding
68
Thresholding
Multivariable Thresholding
Histogram
Using a plane
in 3D
69
Thresholding
Multivariable Thresholding
70
Thresholding
Multivariable Thresholding
• Distance:
- Euclidean distance (hyper-sphere)
1
D(z, a) (z a)T (z a) 2
z z aa
K
1
where C k k
T T
is the covariance matrix
K k 1
K
1
Note: sometimes a is the mean of a region: a
K
z k
k 1
71
Outline
72
Region-Based Segmentation
Region Growing
• Idea: merge pixels (or regions) if they are similar (gray level intensity, color,
texture, …( and connected
• General procedure
- Start with set of “seed” points (with predetermined or distinct properties)
- From seed point grow regions: append neighbor pixels with properties similar
to the seed
73
Region-Based Segmentation
Region Growing
• Example:
The seed for the object is the center of the image. Region is grown when the
difference between two pixel values is less than or equal to 5
74
Region-Based Segmentation
Region Growing
• Example
Region Growing
75
Region-Based Segmentation
Region Growing
• Example
76
Region-Based Segmentation
Region Splitting and Merging
• Procedure:
- For any region Ri, if Q(Ri)=False, divide the region into quadrants
- When no further splitting is possible, merge adjacent regions Rj and Rk if
Q(R j Rk ) = True
- Stop when no further merging is possible
77
Region-Based Segmentation
Region Splitting and Merging
• Example
78
Outline
79
Morphological Watersheds
Watershed lines
• Types of points:
- Points in a regional minimum
- Points where a drop of water would fall to a single minimum (catchment
basin or watershed)
- Points where a drop of water would (equally likely) fall to more than one
minimum (divide lines or watershed lines)
80
Morphological Watersheds
• Idea:
- Punch hole at each regional minimum & flood from bottom
- Construct “dams” at watershed lines to prevent merging
- Stop when maximum gray level is reached
81
Morphological Watersheds
• Example
82
Morphological Watersheds
83
Conclusions
76