cvision 3 image pre-processing: filtering & enhancementmcoimbra/lectures/mapi... · median...

87
Cvision 3 Image Pre-processing: Filtering & Enhancement João Paulo Silva Cunha ([email protected]) IEETA / Universidade de Aveiro

Upload: others

Post on 26-Sep-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

Cvision – 3

Image Pre-processing:

Filtering & Enhancement

João Paulo Silva Cunha([email protected])

IEETA / Universidade de Aveiro

Page 2: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 2

Outline

• Frequency Space

• Spatial Convolution

• Spatial filters

– Gaussian; Oriented Gaussian; Mean; Median

• Frequency domain filtering

• Edge detection

Acknowledgements: Most of this course is based on the excellent courses offered by Prof. Shree Nayar at

Columbia University, USA and by Prof. Srinivasa Narasimhan at CMU, USA. This was also based on Prof.

Miguel Coimbra’s slides. Please acknowledge the original source when reusing these slides for academic

purposes.

Page 3: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 3

Topic: Frequency Space

• Frequency Space

• Spatial Convolution

• Spatial filters

• Frequency domain filtering

• Edge detection

Page 4: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 4

How does this apply to images?

• We have defined the

Fourier Transform as

• But images are:

– Discrete.

– Two-dimensional.

What a computer sees

dxexfuF iux

Page 5: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 5

2D Discrete FT

• In a 2-variable case, the discrete FT pair

is:1

0

1

0

)]//(2exp[),(1

),(M

x

N

y

NvyMuxjyxfMN

vuF

1

0

1

0

)]//(2exp[),(),(M

u

N

v

NvyMuxjvuFyxf

For u=0,1,2,…,M-1 and v=0,1,2,…,N-1

For x=0,1,2,…,M-1 and y=0,1,2,…,N-1

AND:

New matrix

with the

same size!

Page 6: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 6

Frequency Space

• Image Space

– f(x,y)

– Intuitive

• Frequency Space

– F(u,v)

– What does this mean?

Page 7: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 7

Power distribution

An image (500x500 pixels) and its Fourier spectrum. The super-imposed circles have

radii values of 5, 15, 30, 80, and 230, which respectively enclose 92.0, 94.6, 96.4, 98.0,

and 99.5% of the image power.

Page 8: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 8

Power distribution

• Most power is in low frequencies.

• Means we are using more of this:

And less of this:

To represent our signal.

• Why?

Page 9: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 9What does this mean??

Page 10: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 10

Horizontal and Vertical Frequency

• Frequencies:

– Horizontal frequencies

correspond to

horizontal gradients.

– Vertical frequencies

correspond to vertical

gradients.

• What about diagonal

lines?

Page 12: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 12If I discard high-frequencies, I get a blurred image...

Why?

Page 13: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 13

Why bother with FT?

• Great for filtering.

• Great for compression.

• In some situations: Much faster than

operating in the spatial domain.

• Convolutions are simple multiplications in

Frequency space!

• ...

Page 14: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 14

Topic: Spatial Convolution

• Frequency Space

• Spatial Convolution

• Spatial filters

• Frequency domain filtering

• Edge detection

Page 15: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 15

Convolution

fg

gf Eric Weinstein’s Math World

Page 16: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 16

Convolution

1 2-1-2

xc-1 1

1

xb

-1 1

1xa

bac

1

hfgdxhfxg

Page 17: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 17

Convolution Kernel – Impulse Response

• What h will give us g = f ?

f gh hfg

Dirac Delta Function (Unit Impulse)

x

21

0

Page 18: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 18

Point Spread Function

• Ideally, the optical system should be a Dirac delta function.

• However, optical systems are never ideal.

• Point spread function of Human Eyes.

Optical

Systemscene image

x xPSFOptical

Systempoint source point spread function

x

21

0

Page 19: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 19

Point Spread Function

normal vision myopia hyperopia

Images by Richmond Eye Associates

Page 20: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 20

Properties of Convolution

• Commutative

• Associative

• Cascade system

abba

cbacba

f g1h 2h

f g21 hh

f g12 hh

Page 21: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 21

Fourier Transform and Convolution

hfg dxexguG uxi2

dxdexhf uxi2

dxexhdef xuiui 22

'' '22 dxexhdef uxiui

Let Then

uHuF

Convolution in spatial domain

Multiplication in frequency domain

Page 22: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 22

Fourier Transform and Convolution

hfg FHG

fhg HFG

Spatial Domain (x) Frequency Domain (u)

So, we can find g(x) by Fourier transform

g f h

G F H

FT FTIFT

Page 23: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 23

Topic: Spatial filters

• Frequency Space

• Spatial Convolution

• Spatial filters

• Frequency domain filtering

• Edge detection

Page 24: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 24

Images are Discrete and Finite

yxf , yxg ,yxh ,

f

MN

i

j

h

ConvolutionM

m

N

n

njmihnmfjig1 1

,,,

Fourier Transform

M

m

N

n

N

nv

M

mui

enmfvuF1 1

2

,,

Inverse Fourier Transform

M

u

N

v

N

lv

M

kui

evuFMN

lkf1 1

2

,1

,

Page 25: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 25

Spatial Mask

• Simple way to

process an image.

• Mask defines the

processing function.

• Represents a spatial

convolution that

corresponds to a

multiplication in

frequency domain.

Convolution – Mask

‘slides’ over the image

Mask Image

Page 26: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 26

Example (1 pixel)

• Each mask position

has weight w.

• The result of the

operation for each

pixel is given by:

1 2 1

0 0 0

-1 -2 -1

2 2 2

4 4 4

4 5 6

Mask Image

=1*2+2*2+1*2+…

=8+0-20

=-12

a

as

b

bt

tysxftswyxg ),(),(),(

Page 27: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 27

Definitions

• Spatial filters

– Use a mask (kernel) over an image region.

– Work directly with pixels.

– As opposed to: Frequency filters.

• Advantages

– Simple implementation: convolution with the kernel function.

– Different masks offer a large variety of functionalities.

Page 28: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 28

Example (360x500 image)

Page 29: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 29

Example (360x500 image)

Page 30: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 30

Example (360x500 image)

Page 31: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 31

Example (360x500 image)

Page 32: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 32

Convolution Border Issues

Page 33: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 33

• A Gaussian kernel gives less weight to pixels further from the center of the window

• This kernel is an approximation of a Gaussian function:

Gaussian Smoothing

1 2 1

2 4 2

1 2 1

Page 34: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 34

2

8.2 4

original

Page 35: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 35

Gaussian Smoothing (maths)

2

22

2

1

22

1,

ji

ejihGaussian

kernel

N pixels

Filter size N …can be very large

(truncate, if necessary)

1 1

2

1

2,

2

1,

2

22

m n

nm

njmifejig

2D Gaussian is separable!

1 1

2

1

2

1

2,

2

1,

2

2

2

2

m n

nm

njmifeejig

Use two 1D

Gaussian

Filters!

Page 36: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 36

Finite kernel support

Page 37: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 37

Oriented Gaussian Filters

Page 38: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 38

Oriented Gaussian Filters

Page 39: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 39

Oriented Gaussian Filters

Page 41: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 41

Mean Filtering

• We are degrading the

energy of the high spatial

frequencies of an image

(low-pass filtering).

– Makes the image

‘smoother’.

– Used in noise reduction.

• Can be implemented with

spatial masks or in the

frequency domain. 1 1 1

1 1 1

1 1 1

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

Page 42: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 42Mean filter Gaussian filter

Page 43: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 43

http://www.michaelbach.de/ot/cog_blureffects/index.html

by Charles Allen Gillbert by Harmon & Julesz

Page 45: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 45

Median Filter

• Smoothing is averaging

(a) Blurs edges

(b) Sensitive to outliers

(a)

(b)

– Sort values around the pixel

– Select middle value (median)

– Non-linear (Cannot be implemented with convolution)

• Median filtering

12N

sort median

Page 46: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 46

3x3

5x5

7x7

Salt and pepper noise Gaussian noise

Page 47: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 47

Topic: Frequency domain filtering

• Frequency Space

• Spatial Convolution

• Spatial filters

• Frequency domain filtering

• Edge detection

Page 48: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 48

Image Processing in the Fourier

Domain

Does not look anything like what we have seen

Magnitude of the FT

Page 49: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 49

Lets the low frequencies

pass and eliminates the

high frequencies.

Generates image with overall

shading, but not much detail

Low-pass Filtering

Page 50: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 50

Lets through the high

frequencies (the detail),

but eliminates the low

frequencies (the overall

shape). It acts like an

edge enhancer.

High-pass Filtering

Page 51: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 51

Boosting High Frequencies

Page 52: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 52

Topic: Edge detection

• Frequency Space

• Spatial Convolution

• Spatial filters

• Frequency domain filtering

• Oriented Gaussian filters

• Edge detection

Page 53: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 53

Edge Detection

• Convert a 2D image into a set of curves– Extracts

salient features of the scene

– More compact than pixels

Page 54: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 54

Origin of Edges

• Edges are caused by a variety of factors

depth discontinuity

surface color discontinuity

illumination discontinuity

surface normal discontinuity

Page 55: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 55

How can you tell that a pixel is

on an edge?

Page 56: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 56

Image derivatives

Page 57: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 57

Image derivatives

Page 58: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 58

Smooth derivative

Page 59: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 59

Smooth derivative

Page 60: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 60

Smooth derivative

Page 61: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 61

Smooth but …

Page 62: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 62

Gradient

• Gradient equation:

• The edge strength is given

by the gradient magnitude

Page 63: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 63

Gradient

Page 64: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 64

Directional derivatives

Page 65: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 65

Directional derivatives

Page 66: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 66

Laplacian Operator

Page 67: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 67

Operators for edge detection

Page 68: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 68

What is an edge ?

Page 69: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 69

Gradient of an edge

Page 70: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 70

Gradient operator for edge

detection

Page 71: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 71

Gradient operator for edge

detection

Page 72: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 72

Discrete Edge Operators

• How can we differentiate a discrete image?

Finite difference approximations:

1, jiI 1,1 jiI

jiI , jiI ,1

jijijiji IIIIx

I,,11,1,1

2

1

jijijiji IIIIy

I,1,,11,1

2

1

1 1

1 12

1

x

I 1 1

1 12

1

y

I

Convolution masks :

Page 73: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 73

1, jiI 1,1 jiI

jiI , jiI ,1

1,1 jiI

jiI ,1

1,1 jiI 1, jiI 1,1 jiI

• Second order partial derivatives:

jijiji IIIx

I,1,,122

2

21

1,,1,22

2

21

jijiji IIIy

I• Laplacian :

2

2

2

22

y

I

x

II

2

2 1I

Convolution masks :

1 0

4 1

0

1

0 1 0

or26

14 1

20 4

1

4

1 4 1

Discrete Edge Operators

(more accurate)

Page 74: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 74

The Sobel Operators

• Better approximations of the gradients exist

– The Sobel operators below are commonly used

-1 0 1

-2 0 2

-1 0 1

1 2 1

0 0 0

-1 -2 -1

Page 75: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 75

Comparing Edge Operators

-1 0 1

-1 0 1

-1 0 1

1 1 1

0 0 0

-1 -1 1

Gradient:

Roberts (2 x 2):

Sobel (3 x 3):

Sobel (5 x 5):-1 -2 0 2 1

-2 -3 0 3 2

-3 -5 0 5 3

-2 -3 0 3 2

-1 -2 0 2 1

1 2 3 2 1

2 3 5 3 2

0 0 0 0 0

-2 -3 -5 -3 -2

-1 -2 -3 -2 -1

0 1

-1 0

1 0

0 -1

Good Localization

Noise Sensitive

Poor Detection

Poor Localization

Less Noise Sensitive

Good Detection

Page 76: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 76

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??

Page 77: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 77Where is the edge?

Solution: Smooth First

Look for peaks in

Page 78: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 78

Derivative Theorem of Convolution

…saves us one operation.

Page 79: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 79

Laplacian of Gaussian (LoG)

Laplacian of Gaussian operator

Where is the edge? Zero-crossings of bottom graph !

fhx

fhx 2

2

2

2

Laplacian of Gaussian

Page 80: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 80

2D Gaussian Edge Operators

Laplacian of GaussianGaussian

Derivative of Gaussian (DoG)

Mexican Hat (Sombrero)

• is the Laplacian operator:

Page 81: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 81

Canny Edge Operator

• Smooth image I with 2D Gaussian:

• Find local edge normal directions for each pixel

• Compute edge magnitudes

• Locate edges by finding zero-crossings along the edge normal

directions (non-maximum suppression)

IG

IGn

IG

02

2

n

IG

IG

Page 82: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 82

Canny Edge Operator

Page 83: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 83

Canny Edge Operator

Page 84: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 84

Non-local maxima suppression

Page 85: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 85

Non-local maxima suppression

Page 86: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 86

Hysteresis thresholding

Page 87: Cvision 3 Image Pre-processing: Filtering & Enhancementmcoimbra/lectures/MAPI... · Median Filter • Smoothing is averaging (a) Blurs edges (b) Sensitive to outliers (a) (b) –

[email protected] 87

Resources

• Russ – Chapter 8, 9

• Gonzalez & Woods – Chapter 4

• http://homepages.inf.ed.ac.uk/rbf/HIPR2/c

anny.htm