image processing - computer vision edge...

13
Image Processing - Lesson 10 Edge Detection • Edge detection masks • Gradient Detectors • Compass Detectors • Second Derivative - Laplace detectors • Edge Linking • Hough Transform Image Processing Computer Vision Low Level High Level Image Processing - Computer Vision representation, compression,transmission image enhancement edge/feature finding image "understanding" UFO - Unidentified Flying Object Point Detection Convolution with: -1 -1 -1 -1 8 -1 -1 -1 -1 Large Positive values = light point on dark surround Large Negative values = dark point on light surround Example: -1 -1 -1 -1 8 -1 -1 -1 -1 5 5 5 5 5 5 5 5 100 5 5 5 5 5 5 0 0 -95 -95 -95 0 0 -95 760 -95 0 0 -95 -95 -95 * =

Upload: others

Post on 23-Jan-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Image Processing - Lesson 10

Edge Detection

• Edge detection masks

• Gradient Detectors

• Compass Detectors

• Second Derivative - Laplace detectors

• Edge Linking

• Hough Transform

Image Processing

Computer Vision

Low Level

High Level

Image Processing - Computer Vision

representation,compression,transmission

image enhancement

edge/feature finding

image "understanding"

UFO - Unidentified Flying Object Point Detection

Convolution with:-1 -1 -1 -1 8 -1 -1 -1 -1

Large Positive values = light point on dark surroundLarge Negative values = dark point on light surround

Example:

-1 -1 -1 -1 8 -1 -1 -1 -1

5 5 5 5 5 5 5 5 100 55 5 5 5 5

0 0 -95 -95 -95 0 0 -95 760 -950 0 -95 -95 -95

*

=

Page 2: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Edge Definition

Line Edge

gray

val

ue

xedge edge

gray

val

ue

xedge edge

Step Edge

Edge Detection

Line Edge Detectors

Step Edge Detectors

-1 -1 -1 2 2 2

-1 -1 -1

-1 2 -1 -1 2 -1 -1 2 -1

2 -1 -1 -1 2 -1-1 -1 2

-1 -1 2 -1 2 -1 2 -1 -1

-1 1-1 1-1 1

-1 -1 1 1 -1 -1 1 1-1 -1 1 1-1 -1 1 1

-1 -1 -1 -1-1 -1 -1 -11 1 1 11 -1 1 1

-1 -1 -1 -11 1 1 1

-1 -1 1 1 -1 -1 1 1-1 -1 1 1-1 -1 1 1

-1 -1 -1 -1-1 -1 -1 -11 1 1 11 -1 1 1

Example Edge Detection by Differentiation

Step Edge detection by differentiation:

gray

val

ue

x

1D image f(x)

1st derivative f'(x)

threshold|f'(x)| - threshold

Pixels that passed the threshold are

Edge Pixels

Page 3: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Gradient Edge Detection

∇ f((x,y) =

∂f∂x∂f∂y

Gradient

Gradient Magnitude

Gradient Direction

∂f∂x

∂f∂y√( )2 + ( )2

∂f∂y

∂f∂xtg-1 ( / )

∇ f((x,y) = ∂f∂y0 ,

∇ f((x,y) = ∂f∂x , 0

Gradient Edge - Examples

Differentiation in Digital Images

∂f(x,y)∂x = f(x,y) - f(x-1,y)

= f(x,y) - f(x,y-1)∂f(x,y)∂y

horizontal - differentiation approximation:

vertical - differentiation approximation:

convolution with [ 1 -1 ]

convolution with 1-1

FA =

FB =

Gradient (FA , FB)

((FA )2 + (FB)2 )1/2Magnitude

|FA | + |FB|Approx. Magnitude

Example Edge

Original

Gradient-X Gradient-Y

Gradient-Magnitude Gradient-Direction

Page 4: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

FA = f(x,y) - f(x-1,y-1)FB = f(x-1,y) - f(x,y-1)

1 00 -1A = 0 1

-1 0B =

Roberts and other 2x2 operators are sensitive to noise.

Roberts Edge Detector

Smoothed operators

Prewitt Edge Detector

-1 -1 -10 0 01 1 1

B =-1 0 1-1 0 1-1 0 1

A =

Sobel Edge Detector

-1 -2 -10 0 01 2 1

B =-1 0 1-2 0 2-1 0 1

A =

Isotropic Edge Detector

-1 -√2 -10 0 01 √2 1

B =-1 0 1

-√2 0 √2-1 0 1

A =

Edge Detector - Comparison

Original

Roberts

Sobel

Prewitt

Negative MagnitudeMagnitude

Compass Operators

1 1 1 0 0 0

-1 -1 -1

-1 -1 -1 0 0 0 1 1 1

1 1 0 1 0 -10 -1 -1

-1 -1 0 -1 0 10 1 1

1 0 -1 1 0 -11 0 -1

-1 0 1 -1 0 1-1 0 1

0 -1 -1 1 0 -11 1 0

0 1 1 -1 0 1-1 -1 0

N

S

NW

SE

W SW

E NE

Given k operators, gk(x,y) is the image obtained byconvolving f(x,y) with the kth operator.

The gradient is defined as:

g(x,y) = max gk(x,y)k

k defines the edge direction

Page 5: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Various Compass Operators:

1 1 1 1 -2 1

-1 -1 -1

Kirsch Edge Detector

1 1 1 0 0 0

-1 -1 -1

5 5 5 -3 0 -3-3 -3 -3

1 2 1 0 0 0

-1 -2 -1

Kirsch (Compass)

Direction Map Magnitude Negative Magnitude

Original

Edge Detector - Comparison

Sobel

f(x)

f (x)

f (x)

Derivatives

zero crossing

Laplacian Operators

Approximation of second derivative (horizontal):

= f''(x,y) = f'(x+1,y) - f'(x,y) == [f(x+1,y) - f(x,y)] - [f(x,y) - f(x-1,y)] = f(x+1,y) - 2 f(x,y) + f(x-1,y)

∂f2(x,y)∂2x

convolution with: [ 1 -2 1]

Approximation of second derivative (vertical):

convolution with: 1-21

Laplacian Operator ( + )∇2 = ∂2

∂x2∂2

∂y2

convolution with:0 -1 0

-1 4 -10 -1 0

Page 6: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Variations on Laplace Operators:

0 -1 0-1 4 -10 -1 0

1 -2 1-2 4 -21 -2 1

-1 -1 -1-1 8 -1-1 -1 -1

All are approximations of:

Example of Laplacian Edge Detection

- =

Laplacian ~ Difference of gaussians

DOG = Difference of Gaussians

FFT

- =

FFT

- =

Laplacian Operator(Image Domain)

Laplacian Filter(Frequency Domain)

Page 7: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Enhancement Using the Laplacian Operator

Edge Image f(x)

∂f∂x1st derivative

∂2f∂x2

2nd derivative(Laplacian)

∂2f∂x2-

∂2f∂x2f(x) -

Mach Bands

Examples of enhanced imagesOriginal Laplacian Image

Scaled Laplacian Image Enhanced Image

Edge Detection - Noise Issues

)( xf

)( xfdxd

Edge Detection - Noise Issues

Peaks in mark the edge( )fgx

∗∂∂

( )fgx

∗∂∂

fg ∗

g

f

Page 8: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

fhx

∗⎟⎠⎞

⎜⎝⎛

∂∂

f

hx∂

Edge Detection - Noise Issues

( ) fhx

fhx

∗⎟⎠⎞

⎜⎝⎛

∂∂

=∗∂∂

From the convolution theorem we have:

Edge Detection - Noise Issues

Zero Crossings in mark the edge( )fgx

∗∂∂

2

2

f

fgx

∗⎟⎟⎠

⎞⎜⎜⎝

⎛∂∂

2

2

gx 2

2

∂∂

Canny Edge Detector

1) Convolve image with derivative of a Gaussian2) Perform NonMaximum suppression.3) Perform Hysteresis Thresholding.

Convolve image with derivative of a Gaussian

f(x,y) * G'(x,y) ≅ f(x,y) * G'x(x,y) + f(x,y) * G'y(x,y)

1 2 4 2 1 1 -1= f(x,y) * *

Fa = f(x,y) * Gx(x,y) * Dx(x,y)

Fb = f(x,y) * Gy(x,y) * Dy(x,y)

12421

1-1= f(x,y) * *

((FA )2 + (FB)2 )1/2Magnitude

Canny Edge Detector - Step 1

Page 9: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Canny Edge Detector - Step 1

f * Gx f * Gy

Original

f*Gy*Dyf*Gx*Dx

((FA )2 + (FB)2 )1/2

Magnitude

Fb =Fa =

NonMaximum suppression.

xx xx

x

x

Remove edges that are NOT local Maxima in the gradient direction.

Local Maxima Local Maxima

Canny Edge Detector - Step 2

NonMaximum Suppression.

Magnitude NonMaximum Supression

Canny Edge Detector - Step 2

Hysteresis Thresholding.

High Threshold

Low Threshold

Edge Pixel

Non-Edge Pixel

Possible Edge Pixel

Include possible edge pixels that are adjacent to edge pixels.

Canny Edge Detector - Step 3

Page 10: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Low Threshold

HighThreshold

HysteresisThreshold

Magnitude(NonMax

Suppressed)

Canny Edge Detector - Step 3

Canny with σ = 1

original

Effect of σ (Gaussian kernel size)

Effect of Scale

Canny with σ = 2

Gaussian filtered signal

first derivative peaks

Scale SpaceWitkin 83

Properties of Scale Space:• Position of edges may change with scale.• Edges may merge with increase in scale.• Edges do NOT split with increase in scale.

Edge Completion

Page 11: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Edge Linking

(x,y) is an edge pixel.Search for neighboring edge pixels that are "similar".

Similarity:

Similarity in Edge OrientationSimilarity in Edge strength (Gradient Amplitude)

Perform Edge Following along similar edge pixels.(as in Contour Following in binary images).

Examples of edge linking

Original Sobel Vertical

Sobel Horizontal Linked Edges

Edge Points linked: Gradient Value > 25Gradient direction within 15%

Problem:Edges are not lines even when linked.

Edge pixels are not ellipses even when linked.

θ

Hough Transform

x

ys (θ, s)

straight line Hough Transform

Image Domain Hough Domain

y = ax+b

s = xcos(θ)+ysin(θ)

Page 12: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

θ

x

ys (θ, s)

straight line Hough Transform

x

y

single point = many possible lines

θ

s

Image Domain Hough Domain

y = ax+b

Hough Transform

x

y

many points on a line = many lines in the Hough transform space which intersect at 1 point.

s

Hough Transform

θ

Hough Transform Example

Hough Transform (s,θ) space

Original square image

s

θ

Reconstructed line segments

Hough Transform Example

Original Edges

Hough Transform

Results1 Results2 Results3

Page 13: Image Processing - Computer Vision Edge Detectioncs.haifa.ac.il/hagit/courses/ip/Lectures/Ip11_edgex4.pdfEdge Linking (x,y) is an edge pixel. Search for neighboring edge pixels that

Hough Transform for Circles

x

y (x0,y0,r)

circle Hough Transform

Image Domain Hough Domain

r2 = (x-x0)2+(y-y0)2

(x0,y0)r

x0

y0r

Hough Transform Example

Original

Edges

Result

Nice demo: http://www.markschulze.net/java/hough/index.html

3D Perception - Depth Perception

Impossible Figures(Escher)