fourier, filtering, smoothing, and noise

42
Fourier, filtering, smoothing, and noise Nuno Vasconcelos ECE Department, UCSD (with thanks to David Forsyth)

Upload: others

Post on 26-Oct-2021

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fourier, filtering, smoothing, and noise

Fourier, filtering, smoothing, and noise

Nuno Vasconcelos ECE Department, UCSD

(with thanks to David Forsyth)

Page 2: Fourier, filtering, smoothing, and noise

2

Plan for todaywe have talked about some theoretic of 2D DSPtoday we will see examples with real imageswe will:• talk about the discrete-space Fourier transform• sampling in 2D• visualize concepts such as frequency spectra and aliasing• see that very important vision operations are really just filtering,

with some post processing• introduce some important filters that are widely used in practice • talk about the impact of noise and how to deal with it

Page 3: Fourier, filtering, smoothing, and noise

3

The Discrete-Space Fourier Transformis, once again, a straightforward extension of the 1D Discrete-Time Fourier Transform

properties:• basically the same as in 1D (see table in Lim, page 25)• only novelty is separability (homework)

2121221

2121

2211

2211

1 2

),()2(

1],[

],[),(

ωωωωπ

ωω

ωω

ωω

ddeeXnnx

eennxX

njnj

njnj

n n

∫∫

∑∑

=

= −−

)()(),(][][],[ 221121221121 ωωωω XXXnxnxnnx =↔=

Page 4: Fourier, filtering, smoothing, and noise

4

Image spectrumtwo images, the magnitude, and phase of their FTs

Page 5: Fourier, filtering, smoothing, and noise

5

Phase and Magnitudecurious fact• all natural images have about the same magnitude transform• monotonically decaying with frequency

hence, phase seems to matter, but magnitude largely doesn’twe have seen this a little bit in the first problem settook two pictures, swap the phase transforms, compute the inversehere is another example

22

21

211),(ωω

ωω+

∝X

Page 6: Fourier, filtering, smoothing, and noise

6

The importance of phaseReconstruction with zebra

phase, cheetah magnitudeReconstruction with cheetah

phase, zebra magnitude

Page 7: Fourier, filtering, smoothing, and noise

7

Sampling in 2Dconsider an analog signal xc(t1,t2) and let its analog Fourier transform be Xc(Ω1,Ω2)• we use capital Ω to emphasize that this is analog frequency

sample with period (T1,T2) to obtain a discrete-space signal

222111 ;2121 ),(],[TntTntc ttxnnx

===

Page 8: Fourier, filtering, smoothing, and noise

8

Sampling in 2Drelationship between the Discrete-Space FT of x[n1,n2]and the FT of xc(t1,t2) is simple extension of 1D result

DSFT of x[n1,n2] FT of xc(ω1,ω2) “discrete spectrum” “analog spectrum”

Discrete Space spectrum is sum of replicas of analog spectrum• in the “base replica” the analog frequency Ω1 (Ω2) is mapped into

the digital frequency Ω1T1 (Ω2T2)• discrete spectrum has periodicity (2π,2π)

∑ ∑∞

−∞=

−∞=⎟⎟⎠

⎞⎜⎜⎝

⎛ −−=

1 2 1

11

1

11

2121

2,21),(r r

c Tr

TrX

TTX πωπωωω

Page 9: Fourier, filtering, smoothing, and noise

9

For exampleω2

ω1

Ω’T1

Ω”T2

ω1

ω1

Ω’

2π−Ω”T2

2π2π

2π−Ω’T1

Ω2

Ω1

Ω’

Ω”

2

1

''''''

TT

Ω=→ΩΩ=→Ω

βα

no aliasing if

⇔⎩⎨⎧

Ω−≤ΩΩ−≤Ω

22

11

'2'''2'TTTT

ππ

⎩⎨⎧

Ω≤Ω≤

⇔''/'/

2

1

ππ

TT

Page 10: Fourier, filtering, smoothing, and noise

10

Aliasingthe frequency (Ω’/π,Ω’’/π)is the critical sampling frequencybelow it we havealiasing

this is just like the 1D case, but now there are more possibilities for overlap

ω2

ω1

Page 11: Fourier, filtering, smoothing, and noise

11

Reconstructionif there is no aliasing we can recover the signal in a way similar to the 1D case

note: in 2D there are many more possibilities than in 1D• e.g. the sampling grid does not have to be rectangular, e.g.

hexagonal sampling when T2 = T1/sqrt(3) and

• in practice, however, one usually adopts the rectangular grid

( )

( )

( )

( )∑ ∑∞

−∞=

−∞= −

−=

1 2222

2

2222

1111

1111

2121

sinsin],[),(

n nc

TntT

TntT

TntT

TntTnnxtty π

π

π

π

⎩⎨⎧

= ==

otherwise0

odd or even both21;2121

,),(],[ 222111

nnttxnnx TntTntc

Page 12: Fourier, filtering, smoothing, and noise

12

Sampling and aliasing in 2Din summary, sampling is not very different from the 1D case

but aliasing is a lot more fun to look at in imagesit shows up in video too (the wagon wheel effect)

Page 13: Fourier, filtering, smoothing, and noise

13

a sequence of images obtained by down-sampling without any filteringaliasing: the low-frequency parts are replicated throughout the low-res image

Page 14: Fourier, filtering, smoothing, and noise

14

The role of smoothing

none

some

a lot

too little leads to aliasingtoo much leads to loss of information

Page 15: Fourier, filtering, smoothing, and noise

15

Linear Filteringsmoothing is implemented with linear filtersgiven an image x(n1,n2), filtering is the process ofconvolving it with a kernel h(n1,n2)

some very common operations in image processing are nothing but filtering, e.g.• smoothing an image by low-pass filtering• contrast enhancement by high pass filtering• finding image derivatives• noise reduction

),(),(),( 2211212121

knknhkkxnnykk

−−= ∑

Page 16: Fourier, filtering, smoothing, and noise

16

Popular filtersbox function

Fourier transform of a box is the sinc, low-pass filter

side-lobes produce artifacts, smoothed image does not look like the result of defocusing

⎩⎨⎧ −≤≤−≤≤

=otherwise

NnNnnnR xNN 0

10,10,1),( 2211

2121

F

Page 17: Fourier, filtering, smoothing, and noise

17

Example: Smoothing by Averaging

Page 18: Fourier, filtering, smoothing, and noise

18

Camera defocusingif you point an out-of-focus camera at a very small white light (e.g. a light-bulb) at night, you get something like thisthe light can be thought of as an impulsethis must be the impulse responsewell approximated by a Gaussianmore natural filter for image blur than the box

⎟⎟⎠

⎞⎜⎜⎝

⎛ +−= 2

22

2 2exp

21),(

σπσyxyxh

Page 19: Fourier, filtering, smoothing, and noise

19

The Gaussianthe discrete space version is

obviously separable

h(n1,n2) has Fourier transform

⎟⎟⎠

⎞⎜⎜⎝

⎛ +−= 2

22

21

221 2exp

21),(

σπσnnnnh

44344214434421)(

2

)(

221

2

2

22

1

2

21

21

21),(

nh

n

nh

n

eennh σσ

σπσπ

−−×=

⎟⎟⎠

⎞⎜⎜⎝

⎛ +−=

2)(exp),(

22

21

2

21ϖϖσϖϖH

Page 20: Fourier, filtering, smoothing, and noise

20

The Gaussian filterthe Fourier transform of a Gaussian is a Gaussian(σx,σy) ∝ (1/σw1,1/σw2)

F

note that there are no annoying side-lobes

Page 21: Fourier, filtering, smoothing, and noise

21

Smoothing with a Gaussian

Page 22: Fourier, filtering, smoothing, and noise

22

Role of the variancethe variance controls the amount of smoothingeach column shows different realizations of an image of gaussian noiseeach row shows smoothing with gaussians of different σ

Page 23: Fourier, filtering, smoothing, and noise

23

Gradients and edgesfor image understanding, one of the problems is that there is too much information in an image just smoothing is not good enoughhow to detect important (most informative) image points?note that derivatives are large at points of great change• changes in reflectance (e.g. checkerboard pattern)• change in object (an object boundary is different from background)• change in illumination (the boundary of a shadow)

these are usually called edge pointsdetecting them could be useful for various problems• segmentation: we want to know what are object boundaries• recognition: cartoons are easy to recognize and terribly efficient to

transmit

Page 24: Fourier, filtering, smoothing, and noise

24

The importance of edgeslight

reflectance

boundary

Page 25: Fourier, filtering, smoothing, and noise

25

Gradientsfor a 2D function, f(x,y) the gradient at a point (x0,y0)

is the direction of greatest increase at that pointthe gradient magnitude

measures the rate of changeit is large at edges!

T

yxyfyx

xfyxf ⎟⎟

⎞⎜⎜⎝

⎛∂∂

∂∂

=∇ ),(),,(),( 000000

( )Tyx yxfyxf ),(),,( 0000=

f(x,y)

),( 00 yxf∇

),( 11 yxf∇

– large gradient magnitude

– small gradient magnitude

2

)⎟⎟⎠

⎞00

2

002

00 ,(),(),( ⎜⎜⎝

⎛∂∂

+⎟⎠⎞

⎜⎝⎛∂∂

=∇ yxyfyx

xfyxf

Page 26: Fourier, filtering, smoothing, and noise

26

Derivatives and convolutionrecall that a derivative is defined as

linear and shift invariant, so must be the result of a convolution.we could approximate as

where the derivative kernel is

( ) ( ) ( )x

xfxxfxxf

x ∆−∆+

=∂

∂→∆ 0

lim

( ) ( ) ( ) ( ) ( ) )(*11

1 nhfnfnfnfnfnnf

=−+=−+

=∂

)()1()( nnnh δδ −+=

Page 27: Fourier, filtering, smoothing, and noise

27

Finite difference kernelsin two dimensions we have various possible kernelse.g. , N1=2, N2=3, derivative along n1, (line n2=k)(horizontal)

derivative along n2, (line n1=k) (vertical)

derivative along line n1=n2 (diagonal)

n1

n21 -11 -11 -1

0 01 -10 0

n1

n2

0 -1 00 1 0

-1 -1 -11 1 1

n1

n20 0 -10 0 01 0 0

1 -1 00 1 -10 0 1

Page 28: Fourier, filtering, smoothing, and noise

28

Finite difference kernelsnote that, when

h(n1,n2)=

we have

derivative is a high-pass filterhw: check that this holds for all othersintuitive, because a derivative is a measure of the rate of change of a function

222111 ϖϖϖ jjj

eee ⎟⎟⎠

⎞⎜⎜⎝

⎛−=

0 01 -10 0

211

2sin2

ϖϖ je⎟⎠⎞

⎜⎝⎛=

( ) 1, 121 −= ϖϖϖ jeH

Page 29: Fourier, filtering, smoothing, and noise

29

Finite differencesQ: which one do we have here? (gray=0,white=+,dark=-)

Page 30: Fourier, filtering, smoothing, and noise

30

Finite differences and noisebecause they perform high-pass filtering, finite difference filters respond strongly to noisegenerally, the larger the noise the stronger the responsefor noisy images it is usually best to apply some smoothing before computing derivativeswhat do mean by noise? we only consider the simplest model• independent stationary additive Gaussian noise• the noise value at each pixel is given by an independent draw

from the same normal probability distribution

),0(~),,(),(),( 2212121 σεε Nnnnnxnny +=

Page 31: Fourier, filtering, smoothing, and noise

31

sigma=1

Page 32: Fourier, filtering, smoothing, and noise

32

sigma=16

Page 33: Fourier, filtering, smoothing, and noise

33

Finite differences responding to noise

increasing noise variance

note that as the noise variance increases the estimates of the image derivative are also very noisyQ: would a larger filter do better?

Page 34: Fourier, filtering, smoothing, and noise

34

The response of a linear filter to noisesuppose we apply filter h(n1,n2) to

by linearity

consider the noise term

by linearity of expectation

),0(~),,(),(),( 2212121 σεε Nnnnnxnny +=

noiseoutputsignaloutput

hxhyh

ε*** +=

),(),(),( 2211212121

knknhkknnkk

−−= ∑εν

[ ] [ ] 0),(),(),( 2211212121

=−−= ∑ knknhkkEnnEkk

εν

Page 35: Fourier, filtering, smoothing, and noise

35

The response of a linear filter to noiseand since the ε(n1,n2) are independent

output error has• zero mean• variance that increases with the size of the filter and the input

variance

increasing the filter size would definitely not help!

[ ] [ ] ),(),(var),(var 22112

212121

knknhkknnkk

−−=∑ εν

),( 221122

21

knknhkk

−−= ∑σ

Page 36: Fourier, filtering, smoothing, and noise

36

Smoothing reduces noisenoise has a lot of high-frequenciesstrategy:1. start by low-pass filtering, to suppress

noise2. compute derivative on smoothed image

i.e. for a smoothing filter g(n1,n2)compute

note that, by associativity of convolution, this is equal to

i.e. filter the image with the filter h*g

g(n1,n2)

h(n1,n2)

( )xgh **

( ) xgh **smoothed derivatives

Page 37: Fourier, filtering, smoothing, and noise

37

The derivative of a GaussianDoG along n1let’s consider, for example,

in which case

is a difference of two Gaussiansthis is the derivative of a Gaussian (DoG) filterfor other definitions of h we have a similar result

),(),1(),( 212121 nnnnnnh δδ −+=

),(),1(),(* 212121 nngnngnngh −+=DoG along n2

Page 38: Fourier, filtering, smoothing, and noise

38

Smoothed derivativesno smoothing

with smoothing

Page 39: Fourier, filtering, smoothing, and noise

39

Choosing the right scalethe scale of the smoothing filter affects • derivative estimates, • the semantics of the derivative image

trade-off between noise and ability to detect detail

1 pixel 3 pixels 7 pixels

Page 40: Fourier, filtering, smoothing, and noise

40

Page 41: Fourier, filtering, smoothing, and noise

41

Gradients and edgesby now we have a good idea of how to differentiate imagesremember that edges are points of large gradient magnitudeedge detection strategy1. determine magnitude of image gradient

2. mark points where gradient magnitude is particularly large wrt neighbours(ideally, curves of such points)

– large gradient magnitude

– small gradient magnitude

2

00

2

002

00 ),(),(),( ⎟⎟⎠

⎞⎜⎜⎝

⎛∂∂

+⎟⎠⎞

⎜⎝⎛∂∂

=∇ yxyfyx

xfyxf

Page 42: Fourier, filtering, smoothing, and noise

42

Looks easy butthree major issues (to discuss next class):• 1) gradient magnitude at different scales is different (see below);

which should we choose?• 2) gradient magnitude is large along thick trail; what are the

significant points?• 3) how do we link the relevant points up into curves?