11.EdgeDetection
11.EdgeDetection
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 1
Gradient-based edge detection
◼ Idea (continous-space): local gradient magnitude indicates edge strength
f (x, y ) f (x, y )
2 2
(
grad f (x, y ) = )
x
+
y
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 2
Practical edge detectors
◼ Edges can have any orientation
◼ Typical edge detection scheme uses K=2 edge templates
◼ Some use K>2
e x, y
1
Combination,
e.g., edge
s x, y e x, y x, y 2
2 e k
magnitude
k
M x, y
or
Max k ek x, y
e x, y x, y
K (edge orientation)
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 3
Gradient filters (K=2)
0 0 0 0 −1 0
Central 0 1 1 0
−1 0 1 0 0 0 Roberts
Difference −1 0 0 −1
0 0 0 0 1 0
−1 0 1 −1 −1 −1
Prewitt −1 0 1 0 0 0
−1 0 1 1 1 1
−1 0 1 −1 −2 −1
Sobel −2 0 2 0 0 0
−1 0 1 1 2 1
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 4
Kirsch operator (K=8)
+5 +5 +5 +5 +5 −3
−3 +5 −3 −3 −3 −3
Kirsch −3 0 −3 −3 0 +5 −3 0 +5 −3 0 +5
−3 −3 −3 −3 −3 −3 −3 −3 +5 −3 +5 +5
−3 −3 −3 −3 −3 −3
−3 −3 +5 −3 +5 +5
−3 0 −3 +5 0 −3 +5 0 −3 +5 0 −3
+5 +5 +5 +5 +5 −3 +5 −3 −3 −3 −3 −3
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 5
Prewitt operator example
Magnitude of
image filtered with
−1 0 1
−1 0 1
−1 0 1
(log display)
Magnitude of
Original image filtered with
1024x710 −1 −1 −1
0 0 0
1 1 1
(log display)
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 6
Prewitt operator example (cont.)
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 7
Sobel operator example
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 8
Roberts operator example
Magnitude of
image filtered with
1 0
0 −1
(log display)
Magnitude of
Original image filtered with
1024x710 0 1
−1 0
(log display)
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 9
Roberts operator example (cont.)
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 10
Edge orientation
Central
Gradient scatter plot
Difference
0 0 0
−1 0 1
y-component
0 0 0
0 −1 0
0 0 0
0 1 0
x-component
Roberts
0 1
y-component
−1 0
1 0
0 −1
x-component
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 11
Edge orientation
Prewitt Gradient scatter plot
−1 0 1
−1 0 1
1
y-component
−1 0
−1 −1 −1
0 0 0
1 1 1
x-component
Sobel
−1
0 1
−2 0 2
y-component
−1 0 1
−1 −2 −1
0 0 0
1 2 1
x-component
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 12
Edge orientation
Gradient scatter plot
y-component
5x5 “consistent”
gradient operator
[Ando, 2000]
x-component
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 13
Gradient consistency problem
Known
gray
value
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 14
Laplacian operator
◼ Detect edges by considering second derivative
f (x, y)=
2
2
f (x, y )+
2
f (x, y)
x 2
y2
◼ Isotropic (rotationally invariant) operator
◼ Zero-crossings mark edge location
Detect
zero crossing
8 15
6
10
4
|H|
|H|
5
2
0 0
2 2
0 2 0 2
0 0
-2 -2 -2 -2
y x y x
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 16
Zero crossings of Laplacian
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 17
Laplacian of Gaussian
◼ Filtering of image with Gaussian and Laplacian operators can be combined into
convolution with Laplacian of Gaussian (LoG) operator
= 2
1 x +y −
0 .0 2
x2+ y2
( )
2 2
LoG x, y = − 1− e 2 2 0
4
2
2 -0 .0 2
-0 .0 4
-0 .0 6
-0 .0 8
-0.1
4
2 4
0 2
0
-2
-2
Y -4 -4 X
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 18
Discrete approximation of Laplacian of Gaussian
= 2
0 0 1 2 2 2 1 0 0
0 2 3 5 5 5 3 2 0 200
1 3 5 3 0 3 5 3 1
150
2 5 3 -12 -23 -12 3 5 2
|H|
2 5 3 -12 -23 -12 3 5 2
50
1 3 5 3 0 3 5 3 1
0 2 3 5 5 5 3 2 0 0
0 0 1 2 2 2 1 0 0 2
0 2
0
-2 -2
y x
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 19
Zero crossings of LoG
= 2 =2 2 =4 2 =8 2
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 20
Zero crossings of LoG – gradient-based threshold
= 2 =2 2 =4 2 =8 2
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 21
Canny edge detector
1. Smooth image with a Gaussian filter
2. Approximate gradient magnitude and angle (use Sobel, Prewitt . . .)
f 2 2
M x, y f −1 f f
x y + x, y tan
y x
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 22
Canny nonmaxima suppression
◼ Quantize edge normal to one of four directions:
horizontal, -45o, vertical, +45o
◼ If M[x,y] is smaller than either of its neighbors in edge normal direction
➔ suppress; else keep.
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 23
Canny thresholding and suppression of weak edges
◼ Double-thresholding of gradient magnitude
Strong edge: M x, y high
Weak edge: high M x, y low
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 24
Canny edge detector
= 2 =2 2 =4 2
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 25
Hough transform
◼ Problem: fit a straight line (or curve) to a set of edge pixels
◼ Hough transform (1962): generalized template matching technique
◼ Consider detection of straight lines y = mx + c
x m
edge pixel
y
c
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 26
Hough transform (cont.)
◼ Subdivide (m,c) plane into discrete “bins,” initialize all bin counts by 0
◼ Draw a line in the parameter space [m,c] for each edge pixel [x,y] and increment
bin counts along line.
◼ Detect peak(s) in [m,c] plane
x m
detect peak
y
c
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 27
Hough transform (cont.)
◼ Alternative parameterization avoids infinite-slope problem
x
edge pixel
−−
x cos + y sin = 2 2
y
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 28
Hough transform example
100
200
300
400
500
600
700
800
200 400 600 800
Original image
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 29
Hough transform example
100
200
300
400
500
600
700
800
200 400 600 800
Original image
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 30
Hough transform example
100
200
300
400
500
600
700
800
200 400 600 800
Original image
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 31
Hough transform example
-4000 1500
-2000
1000
0
500
2000
De-skewed
Paper Paper
(3264x2448)
4000 0
-50 0 50
-81.8 deg
-81.8 deg
Global thresholding
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 32
Circle Hough Transform
◼ Find circles of fixed radius r
x x0
Circle center
edge pixel
y
y0
◼ Equivalent to convolution (template matching) with a circle
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 33
Circle Hough Transform for unknown radius
◼ 3-d Hough transform for parameters (x0 , y0 ,r )
◼ 2-d Hough transform aided by edge orientation ➔ “spokes” in parameter space
x x0
Circle center
edge pixel
y
y0
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 34
Example: circle detection by Hough transform
Prewitt edge detection Detected circles
Original
coins image
Image Processing: Huynh Trung Tru, © 2023 PTIT HCM -- Edge Detection 35