0% found this document useful (0 votes)
9 views

Lecture-4-Edge-detection-Part-II (2)

Uploaded by

Kush Aggarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lecture-4-Edge-detection-Part-II (2)

Uploaded by

Kush Aggarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

CAP5415

Computer Vision
Yogesh S Rawat
[email protected]
HEC-241

9/14/2021 Lecture 3 –Edge Detection 1


Edge Detection
Part-II

Lecture 4

9/14/2021 Lecture 3 –Edge Detection 2


Edge detection - recap
f

f*g

d
( f  g)
dx

Source: S. Seitz
9/14/2021 Lecture 3 –Edge Detection 3
Edge detection – fewer steps

d
g
dx

d
f g
dx

Source: S. Seitz
9/14/2021 Lecture 3 –Edge Detection 4
Prewitt and Sobel Edge Detector
• Smoothing
• Compute derivatives
• In x and y directions
• Find gradient magnitude
• Threshold gradient magnitude

9/14/2021 Lecture 3 –Edge Detection 5


Discrete derivative - revisit

df
= f ( x) − f ( x − 1) = f ( x) Backward difference
dx

df
= f ( x) − f ( x + 1) = f ( x) Forward difference
dx

df
= f ( x + 1) − f ( x − 1) = f ( x) Central difference
dx

9/14/2021 Lecture 3 –Edge Detection 6


Derivative Masks

Backward difference [-1 1]


Forward difference [1 -1]
Central difference [-1 0 1]

9/14/2021 Lecture 3 –Edge Detection 7


Image derivative
Given function f ( x, y )
 f ( x, y ) 
 x   f x 
Gradient vector f ( x, y ) =  f ( x, y )  =  
   fy 
 y 

Gradient magnitude f ( x, y) = f x2 + f y2

fx
Gradient direction  = tan −1

fy

9/14/2021 Lecture 3 –Edge Detection 8


Prewitt Edge Detector
average derivative
image smoothing in x blurred filtering in x edges in x
1 1
1 1
  1 −1
and 1 0 − 1
1 1
1 0 − 1
 
1 0 − 1

average derivative
image smoothing in y blurred filtering in y edges in y

1 1 1 1 1 1 1
1 1 1  −1 0 0 0
  and    
− 1 − 1 − 1

9/14/2021 Lecture 3 –Edge Detection 9


Sobel Edge Detector
average derivative
image smoothing in x blurred filtering in x edges in x
1 1 
 2 2 1 −1
  and
1 1 1 0 − 1 
 2 0 − 2
 
1 0 − 1

average derivative
image smoothing in y blurred filtering in y edges in y

1 2 1 1 1 2 1
1 2 1  −1 0 0 0 
  and   
− 1 − 2 − 1

9/14/2021 Lecture 3 –Edge Detection 10


Sobel Edge Detector

1 0 − 1 
 2 0 − 2 d
  I
1 0 − 1 dx
*
Threshold Edges
Image I d  d 
2

 I  +  I 
2

 dx   dy 

1 1 d
* 2 I
0 0 0  dy
 
− 1 − 2 − 1

9/14/2021 Lecture 3 –Edge Detection 11


Sobel Edge Detector

d
I
dx

d
I
dy

9/14/2021 Lecture 3 –Edge Detection 12


Sobel Edge Detector

2
d  d 
2

 =  I  +  I 
 dx   dy 

  Threshold = 100

9/14/2021 Lecture 3 –Edge Detection 13


Sobel vs Prewitt

Source: Arbelaez, Maire, Fowlkes, and Malik. TPAMI 2011 (pdf)


9/14/2021 Lecture 3 –Edge Detection 14
Second derivate
• Maxima minima of first derivative
• Zero-crossings of second derivative

1st derivative

2nd derivative

9/14/2021 Lecture 3 –Edge Detection 15


Marr Hildreth Edge Detector
• Smooth image by Gaussian filter
• Apply Laplacian
• Widely used operator
• Find zero crossings
• Scan along each row, record an edge point at the
location of zero-crossing.
• Repeat above step along each column

9/14/2021 Lecture 3 –Edge Detection 16


Marr Hildreth Edge Detector
• Gaussian smoothing
smoothed image
 
Gaussian f ilter 
image

S = g * I

• Find Laplacian 𝑔(𝑥, 𝑦) =


1
𝑒

𝑥 2 +𝑦2
2𝜎 2
second order second order
2𝜋𝜎
deriv ativ ein x deriv ativ ein y
 
•  is used for gradient (derivative)
2 2
S=
2
S + S •  is used for Laplacian
x 2
y 2

9/14/2021 Lecture 3 –Edge Detection 17


Finding Zero Crossings
• Four cases of zero-crossings :
• {+,-}
• {+,0,-}
• {-,+}
• {-,0,+}
• Slope of zero-crossing {a, -b} is |a+b|.
• To mark an edge
• Compute slope of zero-crossing
• Apply a threshold to slope

9/14/2021 Lecture 3 –Edge Detection 18


Marr Hildreth Edge Detector
• Deriving the Laplacian of Gaussian (LoG)

( )
2 S = 2 (g * I ) = 2 g * I

1 𝑥 2 +𝑦 2

𝑔(𝑥, 𝑦) = 𝑒 2𝜎2
2𝜋𝜎

1 𝑥2 + 𝑦2 𝑥 2 +𝑦 2

Δ2 𝑔 𝑥, 𝑦 = − 2− 𝑒 2𝜎2
2𝜋𝜎 3 𝜎2

9/14/2021 Lecture 3 –Edge Detection 19


LoG Filter
x2 + y2
1  x +y 2 2
 −
2G = −  2 − e 2 2

2  3  2 

0.0008 0.0066 0.0215 0.031 0.0215 0.0066 0.0008


0.0066 0.0438 0.0982 0.108 0.0982 0.0438 0.0066
0.0215 0.0982 0 -0.242 0 0.0982 0.0215
0.031 0.108 -0.242 -0.7979 -0.242 0.108 0.031 X
0.0215 0.0982 0 -0.242 0 0.0982 0.0215
0.0066 0.0438 0.0982 0.108 0.0982 0.0438 0.0066
0.0008 0.0066 0.0215 0.031 0.0215 0.0066 0.0008

9/14/2021 Lecture 3 –Edge Detection 20


On the Separability of LoG
• Similar to separability of Gaussian filter
• 2D Gaussian can be separated into 2 one-dimensional Gaussians
h( x, y) = I ( x, y) * g ( x, y) n2 multiplications
1 𝑥 2 +𝑦2

𝑔 𝑥, 𝑦 = 𝑒 2𝜎2
ℎ(𝑥, 𝑦) = 𝐼(𝑥, 𝑦) ∗ 𝑔1 (𝑥) ∗ 𝑔2 (𝑦) 2n multiplications 2𝜋𝜎
1 𝑥2 𝑦2
− −
= 𝑒 2𝜎2 𝑒 2𝜎2
.011 2𝜋𝜎
 .13 
 
 .6 
g1 = .011 .13 .6 1 .6 .13 .011   𝑔1 (𝑥) 𝑔2 (𝑦)
g2 =  1 
 .6 
 
 . 13 
.011
 

9/14/2021 Lecture 3 –Edge Detection 21


On the Separability of LoG
( )
2 S = 2 (g * I ) = 2 g * I = I * 2 g( )
Requires n2 multiplications

Δ2 𝑆 = 𝐼 ∗ 𝑔𝑦𝑦 (𝑦) ∗ 𝑔(𝑥) + 𝐼 ∗ 𝑔𝑥𝑥 (𝑥) ∗ 𝑔(𝑦)

Requires 4n multiplications

9/14/2021 Lecture 3 –Edge Detection 22


Separability
Gaussian Filtering

Image g(x) g(y) + 𝐼∗𝑔

Laplacian of Gaussian Filtering


gyy(y) g(x)

Image + 𝐼 ∗ Δ2 𝑆

gxx(x) g(y)

9/14/2021 Lecture 3 –Edge Detection 23


Algorithm
• Compute LoG
• Use 2D filter 2 g ( x, y)
• Use 4 1D filters g ( x), g xx ( x), g ( y ), g yy ( y )
• Find zero-crossings from each row
• Find slope of zero-crossings
• Apply threshold to slope and mark edges

9/14/2021 Lecture 3 –Edge Detection 24


Example

I I*  g( ) 2
Zero crossings of 2 S

9/14/2021 Lecture 3 –Edge Detection 25


Example

 =1

 =3

 =6

9/14/2021 Lecture 3 –Edge Detection 26


Canny Edge Detector
• Smooth Image with Gaussian filter
• Compute Derivative of filtered image
• Find Magnitude and Orientation of gradient
• Apply Non-max suppression
• Apply Thresholding (Hysteresis)

9/14/2021 Lecture 3 –Edge Detection 27


Canny

9/14/2021 Lecture 3 –Edge Detection 28


Canny-Gradients

X-Derivative of Gaussian Y-Derivative of Gaussian Gradient Magnitude


9/14/2021 Lecture 3 –Edge Detection 29
Gradient Orientation

9/14/2021 Lecture 3 –Edge Detection 30


Non-maximum suppression

If gradient responses at r and p


are smaller than q, q is an edge

9/14/2021 Lecture 3 –Edge Detection 31


Non-maximum suppression
(x, y)
(x, y )
(x, y)

 S (x, y ) if S (x, y )  S (x, y)



M (x, y ) =  & S (x, y )  S (x, y) x’ and x’’ are the neighbors of x along
 normal direction to an edge
0 otherwise

9/14/2021 Lecture 3 –Edge Detection 32


Non-maximum suppression

Before Non-Max Suppression After Non-Max Suppression

9/14/2021 Lecture 3 –Edge Detection 33


Hysteresis Thresholding [L, H]

Gradient High
magnitude

low

9/14/2021 Lecture 3 –Edge Detection 34


Hysteresis Thresholding [L, H]
• If the gradient at a pixel is
• above “High”, declare it as an ‘edge pixel’
• below “Low”, declare it as a “non-edge-pixel”
• between “low” and “high”
• Consider its neighbors iteratively then declare it an “edge pixel” if it is
connected to an ‘edge pixel’ directly or via pixels between “low” and
“high”.

9/14/2021 Lecture 3 –Edge Detection 35


Hysteresis Thresholding [L, H]

x x x

4 connected 8 connected 6 connected

1. Threshold at low/high levels to get weak/strong edge pixels


2. Do connected components, starting from strong edge pixels

9/14/2021 Lecture 3 –Edge Detection 36


Final Canny Edges

9/14/2021 Lecture 3 –Edge Detection 37


Effect of Gaussian Kernel (smoothing)

original Canny with Canny with

The choice of  depends on desired behavior


• large  detects large scale edges
• small  detects fine features
9/14/2021 Lecture 3 –Edge Detection 38
Edge Detection with Deep Learning
• We will revisit edge detection
• After Deep Learning tutorial lectures
• If time permits

9/14/2021 Lecture 3 –Edge Detection 39


Questions?

Sources for this lecture include materials from works by Mubarak Shah,
Abhijit Mahalanobis, and D. Lowe
Other sources from James Hays, Lana Lazebnik, Steve Seitz, David Forsyth, David Lowe, Fei-Fei Li, and Derek Hoiem

9/14/2021 Lecture 3 –Edge Detection 40

You might also like