Top Banner
Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 [email protected]
60
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Edge DetectionGiacomo Boracchi

5/12/2007

[email protected]

Page 2: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Edge Detection in Images

Goal: Automatically find the contour of objects in a scene.

What For: Edges are significant descriptors, useful for classification, compression…

Page 3: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Edge Detection in Images

What is an object?

It is one of the goals of computer vision to identify objects in scenes.

Page 4: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Edges May Have Different Sources

Object Boundaries Occlusions Textures Shading

Page 5: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

What is an Edge

Lets define an edge to be a discontinuity in image intensity function.

Several Models• Step Edge• Ramp Edge• Roof Edge• Spike Edge

They can bethus detected asdiscontinuitiesof image Derivatives

Page 6: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Differentiation and convolution

Recall

Now this is linear and shift invariant. Therefore, in discrete domain, it will be represented as a convolution

xfxf

x

f0

lim

Page 7: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Differentiation and convolution

Recall

Now this is linear and shift invariant, so must be the result of a convolution.

We could approximate this as

(which is obviously a convolution with Kernel

; it’s not a very good way to do things, as we shall see)

xfxf

x

f0

lim x

xfxf

x

f n

1

11

Page 8: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Finite Difference in 2D

yxfyxf

x

yxf ,,lim

,0

yxfyxf

y

yxf ,,lim

,0

x

yxfyxf

x

yxf mnmn

,,, 1

x

yxfyxf

y

yxf mnmn

,,, 1

11

1

1

Discrete Approximation

Horizontal

Convolution Kernels

Vertical

Page 9: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Finite differences

11* II x

1

1*II y

I

Page 10: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Noise

Simplest noise model• independent stationary

additive Gaussian noise• the noise value at each pixel

is given by an independent draw from the same normal probability distribution

Issues• this model allows noise values

that could be greater than maximum camera output or less than zero

• for small standard deviations, this isn’t too much of a problem - it’s a fairly good model

• independence may not be justified (e.g. damage to lens)

• may not be stationary (e.g. thermal gradients in the ccd)

Page 11: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Finite differences and noise

Finite difference filters respond strongly to noise• obvious reason: image noise results in pixels

that look very different from their neighbors

The more relevant is the noise, the stronger the response

Page 12: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Finite differences and noise

What is to be done?• intuitively, most pixels in images look quite a lot

like their neighbors.• this is true even at an edge; along the edge

they’re similar, across the edge they’re not.• suggests that smoothing the image should help,

by forcing pixels different to their neighbors (=noise pixels?) to look more like neighbors.

Page 13: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Finite differences responding to noise

Increasing noise ->(this is zero mean additive gaussian noise)

Page 14: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Finite differences responding to noise

Increasing noise ->(this is zero mean additive gaussian noise)

Page 15: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Finite differences responding to noise

Increasing noise ->(this is zero mean additive gaussian noise)

Page 16: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Smoothing reduces noise

Generally expect pixels to “be like” their neighbors• surfaces turn slowly• relatively few reflectance changes

Generally expect noise processes to be independent from pixel to pixel

Page 17: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Smoothing reduces noise

Generally expect pixels to “be like” their neighbors• surfaces turn slowly• relatively few reflectance changes

Generally expect noise processes to be independent from pixel to pixe

Implies that smoothing suppresses noise, (i.i.d. noise!)

Gaussian Filtering• the parameter in the symmetric Gaussian• as this parameter goes up, more pixels are involved in the average• and the image gets more blurred• and noise is somehow suppressed

Page 18: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

The effects of smoothing Each row shows smoothingwith gaussians of differentwidth; each column showsdifferent realisations of an image of gaussian noise.

Low - Pass

Page 19: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Classical Operators : Prewitt

11

11

11

1

1

11

Smooth Differentiate

101

101

101

111

000

111

111

111

Horizontal

Vertical

Page 20: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Classical Operators: Sobel

11

22

11

1

1

11

Smooth Differentiate

101

202

101

121

000

121

121

121

Horizontal

Vertical

Page 21: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Gaussian Filter

2

22

2 2exp

2

1,

yx

yxG

2

22

2 2

11exp

2

1,

kjki

jiH

array 1212 is , where kkjiH

Page 22: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Sobel Edge Detector

Detecting Edges in Image

Image I

101

202

101

121

000

121

*

*

Idx

d

Idy

d

22

Idy

dI

dx

d

ThresholdEdges

any alternative ?

Discrete Derivatives Gradient NormsThreshold

Page 23: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Quality of an Edge Detector

Robustness to Noise Localization Too Many/Too less Responses

Poor robustness to noise Poor localization Too many responses

True Edge

Page 24: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Canny Edge Detector Criteria

Good Detection: The optimal detector must minimize the probability of false positives as well as false negatives.

Good Localization: The edges detected must be as close as possible to the true edges.

Single Response Constraint: The detector must return one point only for each edge point.

Page 25: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Canny Edge Detector

Basically• Convolution with derivative of Gaussian• Non-maximum Suppression• Hysteresis Thresholding

Page 26: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Canny Edge Detector

Smooth by Gaussian

Compute x and y derivatives

Compute gradient magnitude and orientation

IGS *2

22

2

2

1

yx

eG

Tyx

T

SSSy

Sx

S

22yx SSS

x

y

S

S1tan

Page 27: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Canny Edge Operator

IGIGS ** T

y

G

x

GG

T

Iy

GI

x

GS

**

Page 28: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Canny Edge Detector

xS

yS

I

Page 29: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

The Gradient Orientation

Like for continuous function, the gradient at each pixel points at the steepest intensity growth direction.

The gradient norm indicates the inclination of the intensity growth.

Matlab…..

Page 30: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Canny Edge Detector

I

22yx SSS

25 ThresholdS

Page 31: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

We wish to mark points along the curve where the magnitude is biggest.We can do this by looking for a maximum along a slice normal to the curve(non-maximum suppression). These points should form a curve. There arethen two algorithmic issues: at which point is the maximum, and where is thenext one?

Non-Maximum Suppression - Idea

Page 32: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

We wish to mark points along the curve where the magnitude is biggest.We can do this by looking for a maximum along a slice normal to the curve(non-maximum suppression). These points should form a curve. There arethen two algorithmic issues: at which point is the maximum, and where is thenext one?

Non-Maximum Suppression – Idea (II)

Page 33: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Non-Maximum Suppression - Threshold

Suppress the pixels in ‘Gradient Magnitude Image’ which are not local maximum

edgean tonormaldirection thealong

in of neighbors theare and Sx,yy,xy,x

otherwise0,,&

,, if,

, yxSyxS

yxSyxSyxS

yxM

yx ,

yx,

yx ,

Page 34: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

An Overview on Threshold

According to the way the Threshold T is used they are divided into• Global Threshold• Local (or) Adaptive Threshold

According to the output they can be classified in • Binary Threshold• Hard Threshold• Soft Threshold

Page 35: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Non-Maximum Suppression

22yx SSS M

25ThresholdM

Page 36: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Hysteresis Thresholding

Use of two different threshold High and Low for • For new edge starting point• For continuing edges

In such a way the edges continuity is preserved

Page 37: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Hysteresis Thresholding

If the gradient at a pixel is above ‘High’, declare it an ‘edge pixel’.

If the gradient at a pixel is below ‘Low’, declare it a ‘non-edge-pixel’.

If the gradient at a pixel is between ‘Low’ and ‘High’ then declare it an ‘edge pixel’ if and only if it is connected to an ‘edge pixel’ directly or via pixels between ‘Low’ and ‘ High’.

Page 38: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Hysteresis Thresholding

M 25ThresholdM

15

35

Low

High

Page 39: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Examples

an image its detected edges

Page 40: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

In matlab..

Canny edge detector is implemented with theedge.m command

Page 41: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

A brief overview on Morphological Operators in Image Processing

Giacomo Boracchi

5/12/2007

[email protected]

Page 42: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

An overview on morphological operations

Erosion, Dilation

Open, Closure

We assume the image being processed is binary, as these operators are typically meant for refining “mask” images.

Page 43: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

AND operator in Binary images

Images From Digital Image Processing II edition Gonzalez & Woods Chapter 9

Page 44: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

OR in Binary Images

Page 45: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Erosion

General definition: Nonlinear Filtering procedure that replace to each pixel valuethe maximum on a given neighbor

As a consequence on binary images

E(x)=1 iff the image in the neighbor is constantly 1

This operation reduces thus the boundaries of binary images

It can be interpreted as an AND operation of the image and the neighbor overlapped at each pixel

Page 46: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Erosion Example

Page 47: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Erosion Example

Page 48: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Dilation

General definition: Nonlinear Filtering procedure that replace to each pixel valuethe minimum on a given neighbor

As a consequence on binary images

E(x)=1 iff at least a pixel in the neighbor is1

This operation grows fat the boundaries of binary images

It can be interpreted as an OR operation of the image and the neighbor overlapped at each pixel

Page 49: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Dilation Example

Page 50: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Dilation Example

Page 51: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

In matlab

They are performed using the

bwmorph.m script passing the name of the operation as a parmeter

Examples…

Page 52: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Open and Closure

Open Erosion followed by a Dilation

Closure Dilation followed by an Erosion

Page 53: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Open

Open Erosion followed by a Dilation• Smoothes the contours of an object• Typically eliminate thin protrusions

Page 54: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Open

Figure to Open,

Structuring element a Disk

Page 55: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Open

First Erode,

Page 56: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Open

Then Dilate,

Open results, the bridge has been eliminate from the first erosion and cannot be replaced by the dilation.

Edges are smoothed

Corners are rounded

Page 57: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Closure

Closure Dilation followed by an Erosion• Smoothes the contours of an object, typically creates• Generally fuses narrow breaks

Page 58: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Open

Figure to Open,

Structuring element a Disk

Page 59: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Close

First Dilate,

Page 60: Computer Vision Group Edge Detection Giacomo Boracchi 5/12/2007 boracchi@elet.polimi.it.

Computer Vision Group

Close

Then Erode,

Close results, the bridge has been preserved

Edges are smoothed

Corners are rounded