cits 4402 computer vision · 26/03/2018 computer vision -lecture 05 edge detection & hough...

68
CITS 4402 Computer Vision Ajmal Mian Lecture 05 Edge Detection & Hough Transform 26/03/2018

Upload: others

Post on 06-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

CITS 4402 Computer Vision

Ajmal Mian

Lecture 05

Edge Detection & Hough Transform

26/03/2018

Page 2: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Objectives of this lecture

To understand what are edges

To study the Sobel operator for gradient extraction

To learn the Canny edge detection algorithm

To study the general concept of the Hough transform

To use the Hough transform for line and circle detection

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 2 26/03/2018

Page 3: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Significance of Edges in Images

There is strong evidence that some form of data compression occurs at an

early stage in the human visual system

Research suggests that one form of this compression involves finding

edges and other information-high features in images

From edges we can construct a line drawing of the scene. This results in a

huge data compression, but the information content remains very high

When we look at a sketch of a scene we do not feel that we are missing a

great deal of information

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 3

Page 4: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

What is an Edge?

This is not well defined but the classical approach is to define edges as

being step discontinuities in the image

Edge detection then becomes a task of finding local maxima in the first

derivative or zero-crossing of the 2nd derivative

This idea was first suggested by David Marr at MIT in the late 70’s.

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 4

Page 5: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Edge Detection

Goal: Identify sudden changes

(discontinuities) in an image

– Intuitively, most semantic and shape

information from the image can be encoded

in the edges

– More compact than pixels

Ideal: artist’s line drawing (but artist is also

using object-level knowledge)

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 5

Page 6: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Why do we Care about Edges?

Vanishing point

Vanishing line

Vanishing point

Vertical vanishing point

(at infinity)

Recover geometry and viewpoint

Extract information, recognize objects

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 6

Page 7: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Origin of Edges

Edges are caused by a variety of factors

depth discontinuity

surface color discontinuity

illumination discontinuity

surface normal discontinuity

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 7

Page 8: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia 26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 8

Page 9: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia 26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 9

Page 10: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia 26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 10

Page 11: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia 26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 11

Page 12: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Characterizing Edges

An edge is a place of rapid change in the image intensity function

image intensity function

(along horizontal scanline) first derivative

edges correspond to

extrema of derivative

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 12

Page 13: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Characterizing Edges (cont.)

In a discrete image, we calculate the gradient by taking the difference of

grey values between adjacent pixels

• Forward difference: 𝑔 𝑥 = 𝑓 𝑥 + 1 − 𝑓(𝑥)

• Backward difference: 𝑔 𝑥 = 𝑓 𝑥 − 𝑓(𝑥 − 1)

• Central difference: 𝑔 𝑥 = 𝑓 𝑥 + 1 − 𝑓 𝑥 − 1 /2

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 13

Page 14: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Intensity Profile

Grey levels along the red line Grey level differences along the red line

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 14

Page 15: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

First Derivative Edge Operator

This is equivalent to convolving with the mask

In 2D, the gradient of the image function 𝐼 is given by

𝛻𝐼 =𝜕𝐼

𝜕𝑥,𝜕𝐼

𝜕𝑦

The magnitude is given by 𝜕𝐼

𝜕𝑥

2+

𝜕𝐼

𝜕𝑦

2

The orientation is given by atan2𝜕𝐼

𝜕𝑦,𝜕𝐼

𝜕𝑥

The simplest gradient operator is the Roberts Cross Operator. It uses the

two masks:

-1 +1

0 1

-1 0

1 0

0 -1 and

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 15

Page 16: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Using the Roberts Cross operator…

Input

I

𝜕𝐼

𝜕𝑥1

𝜕𝐼

𝜕𝑥1

2

+𝜕𝐼

𝜕𝑥2

2

𝜕𝐼

𝜕𝑥2

(x2 = 45° line)

(x1 = 135° line)

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 16

Page 17: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

First Derivative Edge Operator (cont.)

Problem determining where to place the result of the convolution:

use an odd number of pixels

A 3 × 3 approximation for 𝜕𝐼

𝜕𝑥 is given by the mask

The well-known Sobel operator is a variation on this theme, giving more

emphasis to the centre cell

-1 0 1

-1 0 1

-1 0 1

-1 0 1

This is the Prewitt operator

-1 0 1

-2 0 2

-1 0 1

1 2 1

0 0 0

-1 -2 -1

for 𝜕𝐼

𝜕𝑦 for

𝜕𝐼

𝜕𝑥

where I is the

greyscale image

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 17

Page 18: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Input

I

𝜕𝐼

𝜕𝑥

𝜕𝐼

𝜕𝑥

2

+𝜕𝐼

𝜕𝑦

2

𝜕𝐼

𝜕𝑦

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 18

Page 19: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

With a Little Gaussian Noise

Gradient

The main problem we have to deal with is noise!

26/03/2018

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 19

Page 20: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Effects of Noise

Consider a single row or column of the image

• Plotting intensity as a function of position gives a signal

Where is

the edge?

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 20

Page 21: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Effects of Noise

Difference filters respond strongly to noise

• Image noise results in pixels that look very different from their neighbors

• Generally, the larger the noise the stronger the response

What can we do about it?

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 21

Page 22: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

f

g

f * g

)( gfdx

d

Edges

correspond to

the peaks in the

derivative of the

Gaussian

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 22

Page 23: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

𝐺

𝐺′

Solution: Smoothen First

1. Convolve the image with a Gaussian mask to smooth it

2. Calculate derivatives of the smoothed image

Both of these operations can be combined into one computationally efficient operation.

If we calculate the derivative of the Gaussian mask and convolve the image with this mask, we compute the derivative of the smoothed image in one hit.

That is, 𝐼 𝐺 ′ = 𝐼 𝐺′

The Prewitt and Sobel operators can be considered to be crude discrete approximations of 𝐺′ over 3 pixels. Use of larger masks allow broader Gaussians to be represented.

derivative

image Gaussian mask

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 23

Page 24: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

• Differentiation is convolution, and convolution is associative:

𝑑

𝑑𝑥𝑓 𝑔 = 𝑓

𝑑

𝑑𝑥(𝑔)

Derivative Theorem of Convolution

Source: S. Seitz

f

𝑑

𝑑𝑥(𝑔)

𝑓 𝑑

𝑑𝑥(𝑔)

LHS: 2 filters:

𝑔 and 𝑑/𝑑𝑥 RHS: 1 filter:

𝑑/𝑑𝑥(𝑔)

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 24

Page 25: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Derivative of a Gaussian Filter

* [1 -1] =

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 25

Page 26: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Tradeoff between Smoothing and Localization

Smoothed derivative removes noise, but blurs edge. Also finds edges at

different “scales”.

1 pixel 3 pixels 7 pixels

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 26

Page 27: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

x

x

x

I

𝜕𝐼/𝜕𝑥

𝜕2𝐼/𝜕𝑥2 edge at zero crossing

A maximum of the 1st derivative will occur at a zero crossing of the 2nd derivative

To get horizontal and vertical edges we look at 2nd derivative in both x and y directions. This is the Laplacian of I :

𝛻2𝐼 =𝜕2𝐼

𝜕𝑥2+𝜕2𝐼

𝜕𝑦2

Second Derivative Edge Operators

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 27

Page 28: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Gausian 𝐺

1st deriv. 𝐺′

2nd deriv. 𝐺′′

Second Derivative Edge Operators (cont.)

The Laplacian is linear and rotationally symmetric

Again we need to consider about smoothing the image with a Gaussian

filter. It is well known that 𝛻2 𝐺 ⊗ 𝐼 = 𝛻2𝐺 ⊗ 𝐼

𝛻2𝐺 is known as the Laplacian of the Gaussian operator

Surface profile of G’’

(the surface has been flipped

upward for visualization)

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 28

Page 29: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Second Derivative Edge Operators (cont.)

Surface profiles of 𝐺, 𝐺′, and 𝐺′′

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 29

Page 30: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

LoG Operator – An Example

A 7 x 7 LoG operator

Input image

Convolution output

(binary edge map.

Dark pixels denote

edge pixels)

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 30

Page 31: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

off-centre, on-surround on-centre, off-surround

Second Derivative Edge Operators (cont.)

This operator became widely used, because…

1. Researchers found receptive fields in animals that behaved like this operator

2. The operator was symmetric – you find edges in all orientations

3. Zero crossings of the 2nd derivative always form closed contours

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 31

Page 32: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Second Derivative Edge Operators (cont.)

However there are some problems

1. Being a 2nd derivative operator, the influence of noise is considerable

2. There are many other types of receptive fields in the eye, so this is not

the whole story

3. Always generating closed contours is not realistic

4. It will mark edges at some locations which are not edges

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 32

Page 33: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Designing an Edge Detector

• Criteria for a good edge detector:

• Good detection: the optimal detector should find all real edges,

ignoring noise or other artifacts

• Good localization

– the edges detected must be as close as possible to the true edges

– the detector must return one point only for each true edge point

Cues of edge detection

• Differences in color, intensity, or texture across the boundary

• Continuity and closure

• High-level knowledge

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 33

Page 34: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

The Canny Edge Detector

This is the current ‘standard’ and is used widely

Devised by John Canny as part of his Masters thesis at MIT in 1983

He treated edge detection as an optimization problem – maximize the

detection of step edges in the presence of noise. The optimization criteria

are:

1. Maximize signal to noise ratio – good detection

2. Good localization of edges – be accurate

3. Minimize number of responses to a single edge in the presence of

noise – avoid false positives

Canny came up with a function that optimized his 3 criteria that was the sum

of 4 exponential terms. However, this function looked very much like the 1st

derivative of a Gaussian ! So this is what ended up being used.

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 34

Page 35: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

The Canny Edge Detector

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 35

Original image

Smoothing by Gaussian convolution

Differential operators along x and y axis

Non-maximum suppression

finds peaks in the image gradient

Hysteresis thresholding locates edge strings

Edge map

Page 36: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Hysteresis Thresholding

Threshold to eliminate ‘insignificant edges’

This involves using two threshold values with one being 2-3 times as large

as the other.

Any pixel with an edge gradient greater than the higher threshold is

considered a valid edge point

Any pixels connected to a valid edge point with a gradient value greater

than the lower threshold is also considered a valid edge point.

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 36

Page 37: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Example

original image (Lena)

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 37

Page 38: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Derivative of Gaussian Filter

x-direction y-direction

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 38

Page 39: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Compute Gradients (DoG)

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

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 39

Page 40: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Get Orientation at Each Pixel

Threshold at minimum level

Get orientation

theta = atan2(gy, gx)

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 40

Page 41: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Non-maximum Suppression for Each Orientation

At q, we have a

maximum if the

value is larger than

those at both p and

at r. Interpolate to

get these values.

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 41

Page 42: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Before Non-max Suppression

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 42

Page 43: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

After non-max suppression

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 43

Page 44: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Hysteresis thresholding

Threshold at low/high levels to

get weak/strong edge pixels

Do connected components,

starting from strong edge pixels

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 44

Page 45: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Final Canny Edges

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 45

Page 46: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Effect of (Gaussian kernel spread/size)

The choice of depends on desired behavior

• large detects large scale edges

• small detects fine features

Canny with Canny with original 26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 46

Page 47: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Comparisons…

outim1=edge(im,’prewitt’);

outim2=edge(im,’sobel’);

outim3=edge(im,’log’);

outim4=edge(im,’canny’);

Outputs from Prewitt and

Sobel can be improved by

adjusting the threshold

values

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 47

Page 48: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

outim1=edge(im,’prewitt’);

outim2=edge(im,’sobel’);

outim3=edge(im,’log’);

outim4=edge(im,’canny’);

Outputs from Prewitt and

Sobel can be improved by

adjusting the threshold

values

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 48

Page 49: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

outim1=edge(im,’prewitt’);

outim2=edge(im,’sobel’);

outim3=edge(im,’log’);

outim4=edge(im,’canny’);

Outputs from Prewitt and

Sobel can be improved by

adjusting the threshold

values

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 49

Page 50: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Problems with Gradient Based Edge Detectors

1. You have to choose threshold values.

If you double the size of an image leaving its grey values unchanged, all

the gradient values will be halved…

2. You have to choose the amount of Gaussian smoothing (also known

as the scale of analysis). This also affects gradients and hence the choice

of threshold values. Also affects the perceived feature positions.

3. Corners are often missed because the 1D gradient at corners is usually

small.

4. 1st derivative operators will only find step-like features. There are

many feature types, e.g. lines.

There are still new edge detection methods proposed today, but gradient

based methods remain by far the most widely used ones.

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 50

Page 51: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Analyzing Edge Images

We have only found edge points

How can we find and describe more complex features (e.g. straight lines)?

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 51

Page 52: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Hough Transform

Each straight line in this image can be described

by an equation

Each white point if considered in isolation could lie

on an infinite number of straight lines

The idea of the Hough transform is that each point

‘votes’ for every line that could pass through it.

The equation of the line that gets most votes

‘wins’.

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 52

Page 53: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

cmxy

),( ii yx

y

x

Equation of Line:

Find:

Consider point:

cmxy

),( cm

),( ii yx

iiii ymxcorcmxy

m

c

),( cm

Image Space

Parameter Space

Parameter space also called Hough Space

Image and Parameter Spaces

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 53

Page 54: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

y

x

),( cm

Parameter Space

1 1

1 1

1 1

2

1 1

1 1

1 1

),( cmA

1. Quantize Parameter Space

2. Create Accumulator Array

3. Set

4. For each image edge increment:

if lies on the line:

6. Find local maxima in

),( cm

),( cmA

cmcmA ,0),(

),( ii yx

1),(),( cmAcmA

),( cm

),( cmA

ii ymxc

Hough Transform – Algorithm

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 54 26/03/2018

Page 55: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

NOTE:

Large Accumulator

More memory and computations

Improvement:

Line equation:

Here

Given points find

m

0sincos yx

max0

20

(Finite Accumulator Array Size)

),( ii yx ),(

),( ii yx

y

xImage Space

Hough Space

?

Better Parameterization

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 55 26/03/2018

Page 56: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Image space Votes (Horizontal axis is θ, vertical is rho)

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 56 26/03/2018

Page 57: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia Computer Vision - Lecture 05 - Edge Detection & Hough Transform 57

Image space Votes (Horizontal axis is θ, vertical is rho)

26/03/2018

Page 58: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia Computer Vision - Lecture 05 - Edge Detection & Hough Transform 58

Image space Votes (Horizontal axis is θ, vertical is rho)

26/03/2018

Page 59: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

• Difficulties

– how big should the cells

be? (too big, and we

merge quite different lines;

too small, and noise

causes lines to be missed)

– small cell sizes => more

computation!

– large cell sizes => less

accuracy!

• How many lines?

– Count the peaks in the

Hough array

– Treat adjacent peaks as

a single peak, i.e. must

perform non-maximum

suppression

Mechanics of the Hough transform

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 59 26/03/2018

Page 60: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Fewer votes land in a single bin when noise increases.

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 60 26/03/2018

Page 61: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Adding more clutter increases number of bins with false peaks.

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 61 26/03/2018

Page 62: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Original Edge Detection Found Lines

Hough Line Detection

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 62

http://homepages.inf.ed.ac.uk/rbf/HIPR2/linedetdemo.htm

26/03/2018

Page 63: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Finding Circles by Hough Transform

Equation of Circle:

If radius is known: (2D Hough Space)

• Accumulator Array

If radius is not known: 3D Hough Space!

• Use Accumulator array

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 63

222 )()( rbyax ii

),( baA

http://www.markschulze.net/java/hough/

),,( rbaA

26/03/2018

Page 64: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Original Edges (note noise)

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 64 26/03/2018

Page 65: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Finding Coins

Note that because the quarters and penny are different sizes, a different Hough transform (with separate accumulators) was used for each circle size.

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 65 26/03/2018

Page 66: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Week 5 Lab

26/03/2018

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 66

Page 67: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Week 5 Lab

Detect circles in images e.g. the pupil or bicycle tyres.

You will need to do edge detection first. Use a popup menu to choose an

edge detection algorithm (min two options) and a slidebar to adjust the

threshold of the edge detector. See lab sheet for details.

Another slide bar should vary the approximate radius for the Hough circle

detection. Show the detected circles on both images.

You are allowed to use the Matlab inbuilt circle detection function.

Marks distribution:

• GUI that can at least load/display an image – 1 mark

• Detect edges with button – 1 mark

• Detect edges with slide bar – 1 mark

• Detect circles with slide bar – 2 marks

26/03/2018

Computer Vision - Lecture 05 - Edge Detection & Hough Transform 67

Page 68: CITS 4402 Computer Vision · 26/03/2018 Computer Vision -Lecture 05 Edge Detection & Hough Transform 33 . The University of Western Australia The Canny Edge Detector This is the current

The University of Western Australia

Summary

Image edges

Sobel operator

Canny edge detection

Hough transform

Line and circle detection

26/03/2018 Computer Vision - Lecture 05 - Edge Detection & Hough Transform 68

Acknowledgements: The slides are based on previous lectures by A/Prof Du Huynh and

Prof Peter Koveski. Other material has been taken from Wikipedia, computer vision

textbook by Forsyth & Ponce, and OpenCV documentation.