immagini e filtri lineari. image filtering modifying the pixels in an image based on some function...

46
Immagini e filtri lineari

Post on 20-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Immagini e filtri lineari

Page 2: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Image Filtering

• Modifying the pixels in an image based on some function of a local neighborhood of the pixels

10 30 10

20 11 20

11 9 1

p

N(p)

5.7 pf

Page 3: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Linear Filtering

• The output is the linear combination of the neighborhood pixels

• The coefficients of this linear combination combine to form the “filter-kernel”

pNq

ii

i

qapf

1 3 0

2 10 2

4 1 1

Image

1 0 -1

1 0.1 -1

1 0 -1Kernel

= 5

Filter Output

Page 4: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Convolution

k l

ljkiHlkIHIjif ,,*,

Kernel

Image

H

I H7 H8 H9

H4 H5 H6

H1 H2 H3

H9 H8 H7

H6 H5 H4

H3 H2 H1

H1 H2 H3

H4 H5 H6

H7 H8 H9

H

flipX

flipY

I1 I2 I3

I4 I5 I6

I7 I8 I9

192837

465564

738291

*

HIHIHI

HIHIHI

HIHIHIHI

I

Page 5: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Linear Filtering

0 0 0

0 1 0

0 0 0

*

Page 6: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Linear Filtering

0 0 0

0 0 1

0 0 0

*

Page 7: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Linear Filtering

1 1 1

1 1 1

1 1 19

1*

Page 8: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Linear Filtering

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

25

1*

Page 9: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120
Page 10: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

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 11: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Linear Filtering(Gaussian Filter)

*

Page 12: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Gaussian Vs Average

Gaussian Smoothing Smoothing by Averaging

Page 13: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Noise Filtering

Gaussian Noise

After Gaussian Smoothing

After Averaging

Page 14: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Noise Filtering

Salt & Pepper Noise

After Gaussian Smoothing

After Averaging

Page 15: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Shift Invariant Linear Systems

• Superposition

• Scaling

• Shift Invariance

gRfRgfR

fkRkfR

Page 16: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120
Page 17: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120
Page 18: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Fourier Transform

dxdyeyxgvuyxgF vyuxi

2,,,:Continuous

Discrete

Page 19: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

F g x, y u, v g x, y e i2 uxvy dxdyR 2

The Fourier Transform

• Represent function on a new basis– Think of functions

as vectors, with many components

– We now apply a linear transformation to transform the basis• dot product with each

basis element

• In the expression, u and v select the basis element, so a function of x and y becomes a function of u and v

• basis elements have the form

e i2 uxvy

Page 20: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120
Page 21: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Here u & v are larger than the previous slide

Larger than the upper example

Page 22: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120
Page 23: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Cheetah ImageFourier Magnitude (above)Fourier Phase (below)

Page 24: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Zebra ImageFourier Magnitude (above)Fourier Phase (below)

Page 25: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Reconstruction withZebra phase,Cheetah Magnitude

Page 26: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Reconstruction withCheetah phase,Zebra Magnitude

Page 27: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Various Fourier Transform Pairs• Important facts

– The Fourier transform is linear

– There is an inverse FT– if you scale the function’s

argument, then the transform’s argument scales the other way. This makes sense --- if you multiply a function’s argument by a number that is larger than one, you are stretching the function, so that high frequencies go to low frequencies

– The FT of a Gaussian is a Gaussian.

• The convolution theorem– The Fourier transform of

the convolution of two functions is the product of their Fourier transforms

– The inverse Fourier transform of the product of two Fourier transforms is the convolution of the two inverse Fourier transforms

Page 28: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Various Fourier Transform Pairs

Page 29: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Aliasing

• Can’t shrink an image by taking every second pixel

• If we do, characteristic errors appear – In the next few slides– Typically, small phenomena look bigger; fast

phenomena can look slower– Common phenomenon

• Wagon wheels rolling the wrong way in movies• Checkerboards misrepresented in ray tracing• Striped shirts look funny on colour television

Page 30: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Resample the checkerboard by taking one sample at each circle. In the case of the top left board, new representation is reasonable. Top right also yields a reasonable representation. Bottom left is all black (dubious) and bottom right has checks that are too big.

Page 31: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Constructing a pyramid by taking every second pixel leads to layers that badly misrepresent the top layer

Page 32: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Sampling in 1D takes a continuous function and replaces it with a vector of values, consisting of the function’s values at a set of sample points. We’ll assume that these sample points are on a regular grid, and can place one at each integer for convenience.

Sampling in 1D

Page 33: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Sampling in 2D does the same thing, only in 2D. We’ll assume that these sample points are on a regular grid, and can place one at each integer point for convenience.

Sampling in 2D

Page 34: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Convolution

0 0 0

0 1 0

0 0 0

*

Page 35: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Convolution

0 0 0

0 0 1

0 0 0

*

Page 36: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120
Page 37: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120
Page 38: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Nyquist Theorem• In order for a band-limited (i.e., one with a zero

power spectrum for frequencies f > B) baseband ( f > 0) signal to be reconstructed fully, it must be sampled at a rate f 2B . A signal sampled at f = 2B is said to be Nyquist sampled, and f =2B is called the Nyquist frequency. No information is lost if a signal is sampled at the Nyquist frequency, and no additional information is gained by sampling faster than this rate.

Page 39: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Smoothing as low-pass filtering• The message of the NT is

that high frequencies lead to trouble with sampling.

• Solution: suppress high frequencies before sampling– multiply the FT of the

signal with something that suppresses high frequencies

– or convolve with a low-pass filter

• A filter whose FT is a box is bad, because the filter kernel has infinite support

• Common solution: use a Gaussian– multiplying FT by

Gaussian is equivalent to convolving image with Gaussian.

Page 40: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Sampling without smoothing. Top row shows the images,sampled at every second pixel to get the next; bottom row shows the magnitude spectrum of these images.

Page 41: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

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 42: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Sampling with smoothing. Top row shows the images. Weget the next image by smoothing the image with a Gaussian with sigma 1 pixel,then sampling at every second pixel to get the next; bottom row shows the magnitude spectrum of these images.

Page 43: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Sampling with smoothing. Top row shows the images. Weget the next image by smoothing the image with a Gaussian with sigma 1.4 pixels,then sampling at every second pixel to get the next; bottom row shows the magnitude spectrum of these images.

Page 44: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Approximate Gaussian

0

0,05

0,1

0,15

0,2

0,25

0,3

0,35

0,4

c b a b c

Gaussian

Page 45: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

What about 2D? Separability of Gaussian

yxGyxIyxI ,*,,

Requires n2 k2 multiplications for n by n image and k by k kernel.

)(**,, yGxGyxIyxI

Requires 2kn2 multiplications for n by n image and k by k kernel.

Page 46: Immagini e filtri lineari. Image Filtering Modifying the pixels in an image based on some function of a local neighborhood of the pixels 103010 201120

Algorithm

• Apply 1D mask to alternate pixels along each row of image.

• Apply 1D mask to alternate pixels along each colum of resultant image from previous step.