of 41 /41
E.G.M. Petrakis Filtering 1 Linear Systems Many image processing (filtering) operations are modeled as a linear system Linear System h(x,y) δ(x,y) dxdy y y x x h y x f y x h y x f y x g ∫∫ = = ) , ( ) , ( ) , ( ) , ( ) , (

vuduong
• Category

## Documents

• view

225

0

Embed Size (px)

### Transcript of Linear Systems - TUCpetrakis/courses/computervision/filtering.pdf · E.G.M. Petrakis Filtering 1... E.G.M. Petrakis Filtering 1

Linear Systems

• Many image processing (filtering) operations are modeled as a linear system

Linear System h(x,y)δ(x,y)

dxdyyyxxhyxf

yxhyxfyxg

∫∫∞−

′−′−′′

=∗=

),(),(

),(),(),( E.G.M. Petrakis Filtering 2

Impulse Response

• System’s output to an impulse δ(x,y)

δ(x,y)

t

I

0 E.G.M. Petrakis Filtering 3

Space Invariance

• g(x,y) remains the same irrespective of the position of the input pulse

• Linear Space Invariance (LSI)

Space Inv. Syst.δ(x-x0,y-y0) h(x-x0,y-y0)

LSI Systemaf1(x,y)+bf2(x,y) ah1(x,y)+bh2(x,y) E.G.M. Petrakis Filtering 4

Discrete Convolution

• The filtered image is described by a discrete convolution

• The filter is described by a n x m discrete convolution mask

∑∑==

−−

=∗=m

l

n

kljkihlkf

jihjifjig

11),(),(

),(),(),( E.G.M. Petrakis Filtering 5

Computing Convolution• Invert the mask g(i,j) by 180o

– not necessary for symmetric masks• Put the mask over each pixel of f(i,j)• For each (i,j) on image

h(i,j)=Ap1+Bp2+Cp3+Dp4+Ep5+Fp6+Gp7+Hp8+Ip9 E.G.M. Petrakis Filtering 6

Image Filtering

• Images are often corrupted by random variations in intensity, illumination, or have poor contrast and can’t be used directly

• Filtering: transform pixel intensity values to reveal certain image characteristics– Enhancement: improves contrast– Smoothing: remove noises– Template matching: detects known patterns E.G.M. Petrakis Filtering 7

Template Matching

• Locate the template in the image E.G.M. Petrakis Filtering 8

Computing Template Matching

• Match template with image at every pixel– distance 0 : the template matches the image

at the current location

– t(x,y): template– M,N size of the template

( ) ( ) ( )[ ]∑∑=′ =′

−′−′−′′=m

x

n

y

yyxxtyxfyxD0 0

22 ,,, E.G.M. Petrakis Filtering 9

( )

( ) ( )[ ]

( )

( )

( ) ( )∑∑

∑∑

∑∑

∑∑

=′ =′

=′ =′

=′ =′

=′ =′

−′−′′′

−−′−′

+′′

=−′−′−′′

=

M

x

N

y

M

x

N

y

M

x

N

y

M

x

N

y

yyxxtyxf

yyxxt

yxf

yyxxtyxf

yxD

1 1

1 1

2

1 1

2

1 1

2

2

,,2

,

,

,,

,

background

constant

correlation:convolution of

f(x,y) with t(-x,-y) E.G.M. Petrakis Filtering 10

true best match

0000005000001010011100011

−−−−−−−−−−−−−

667853

375354

111111111

template image correlation

false matchnoise E.G.M. Petrakis Filtering 11

Observations

• If the size of f(x,y) is n x n and the size of the template is m x m the result is accumulated in a (n-m-1) x (n+m-1) matrix

• Best match: maximum value in the correlation matrix but,– false matches due to noise E.G.M. Petrakis Filtering 12

Disadvantages of Correlation• Sensitive to noise• Sensitive to variations in orientation and scale• Sensitive to non-uniform illumination• Normalized Correlation (1:image, 2:template):

– E : expected value

( ) ( ) ( ) ( )( ) ( )21

2121,qq

qEqEqqEyxNσσ

−=

( ) ( ) ( )[ ] 2122 qEqEq −=σ E.G.M. Petrakis Filtering 13

Histogram Modification

• Images with poor contrast usually contain unevenly distributed gray values

• Histogram Equalization is a method for stretching the contrast by uniformly distributing the gray values– enhances the quality of an image – useful when the image is intended for viewing– not always useful for image processing E.G.M. Petrakis Filtering 14

Example

• The original image has very poor contrast– the gray values are in a very small range

• The histogram equalized image has better contrast E.G.M. Petrakis Filtering 15

Histogram Equalization Methods

• Background Subtraction: subtract the “background” if it hides useful information– f’(x,y) = f(x,y) – fb(x,y)

• Static & Dynamic histogram equalization methods – Histogram scaling (static)– Statistical scaling (dynamic) E.G.M. Petrakis Filtering 16

Static Histogram Scaling

• Scale uniformly entire histogram range:– [z1,zk]: available range of gray values:– [a,b]: range of intensity values in image:– scale [a,b] to cover the entire range [z1,zk]– for each z in [a,b] compute

– the resulting histogram may have gaps

11 )(' zaz

abzzz k +−

−−

= E.G.M. Petrakis Filtering 17

Statistical Histogram Scaling

• Fills all histogram bins continuously– pi : number of pixels at level zi input histogram – qi : number of pixels at level zi output histogram– k1= k2=… : desired number of pixels in histogram bin

• Algorithm:1. Scan the input histogram from left to right to find k1:

– all pixels with values z1,z2,…,zk-1 become z1

∑∑=

=

<≤11

11

1

1

k

ii

k

ii pqp E.G.M. Petrakis Filtering 18

Algorithm (conted)

2. Scan the input histogram from k1 and to the right to find k2:

– all pixels zk1,zk1+1,…,zk2 become z2

• Continue until the input histogram is exhausted– might also leave gaps in the histogram

∑∑=

=

<+≤22

121

1

1

k

ii

k

ii pqqp E.G.M. Petrakis Filtering 19

Noise

• Images are corrupted by random variations in intensity values called noise due to non-perfect camera acquisition or environmental conditions.

• Assumptions: – Additive noise: a random value is added at each

pixel– White noise: The value at a point is

independent on the value at any other point. E.G.M. Petrakis Filtering 20

Common Types of Noise

Salt and pepper noise: random occurrences of both black and white intensity valuesImpulse noise: random occurrences of white

intensity valuesGaussian noise: impulse noise but its intensity

values are drawn from a Gaussian distributionnoise intensity value: k: random value in [a,b]σ : width of Gaussianmodels sensor noise (due to camera electronics)

22

2

),( σk

eyxg−

= E.G.M. Petrakis Filtering 21

Examples of Noisy Images

a. Original imageb. Original imagec. Salt and pepper noised. Impulse noisee. Gaussian noise E.G.M. Petrakis Filtering 22

Noise Filtering

• Basic Idea: replace each pixel intensity value with an new value taken over a neighborhood of fixed size– Mean filter– Median filter

• The size of the filter controls degree of smoothing– large filter large neighborhood intensive

smoothing E.G.M. Petrakis Filtering 23

Mean Filter

• Take the average of intensity values in a m xn region of each pixel (usually m = n)– take the average as the new pixel value

– the normalization factor mn preserves the range of values of the original image

( ) ( )∑∑∈ ∈

=mk nl

lkfmn

jih ,1, E.G.M. Petrakis Filtering 24

Mean Filtering as Convolution

• Compute the convolution of the original image with

– simple filter, the same for all types of noise– disadvantage: blurs image, detail is lost

( )

⋅=

111111111

331, jig E.G.M. Petrakis Filtering 25

Size of Filter

• The size of the filter controls the amount of filtering (and blurring).– 5 x 5, 7 x 7 etc.

– different weights might also be used– normalize by sum of weights in filter

⋅=

1111111111111111111111111

551),( jig E.G.M. Petrakis Filtering 26

Examples of Smoothing

• From left to right: results of 3 x 3, 5 x 5 and 7 x 7 mean filters E.G.M. Petrakis Filtering 27

Median Filter

• Replace each pixel value with the median of the gray values in the region of the pixel:

1. take a 3 x 3 (or 5 x 5 etc.) region centered around pixel (i,j)

2. sort the intensity values of the pixels in the region into ascending order

3. select the middle value as the new value of pixel (i,j) E.G.M. Petrakis Filtering 28

Computation of Median Values

• Very effective in removing salt and pepper or impulsive noise while preserving image detail

• Disadvantages: computational complexity, non linear filter E.G.M. Petrakis Filtering 29

Examples of Median Filtering

• From left to right: the results of a 3 x 3, 5 x 5 and 7 x 7 median filter E.G.M. Petrakis Filtering 30

Gaussian Filter• Filtering with a m x m mask

– the weights are computed according to a Gaussian function:

– σ is user defined22

22

),( σ

ji

ecjig+−

⋅=

14710741412263326124726557155267

1033719171331072655715526741226332612414710741

Example:m = n = 7σ2 = 2 E.G.M. Petrakis Filtering 31

Properties of Gaussian Filtering• Gaussian smoothing is very effective for removing

Gaussian noise• The weights give higher significance to pixels near the

edge (reduces edge blurring)• They are linear low pass filters• Computationally efficient (large filters are implemented

using small 1D filters) • Rotationally symmetric (perform the same in all directions)• The degree of smoothing is controlled by σ (larger σ for

more intensive smoothing) E.G.M. Petrakis Filtering 32

• A 3-D plot of a 7 x & Gaussian mask: filter symmetric and isotropic E.G.M. Petrakis Filtering 33

Gaussian Smoothing

• The results of smoothing an image corrupted with Gaussian noise with a 7 x 7 Gaussian mask E.G.M. Petrakis Filtering 34

Computational Efficiency

• Filtering twice with g(x) is equivalent to filtering with a larger filter with

• Assumptions

( ) ( ) ( )( ) ( ) ( ) ( )yxgyxgyxfyxh

yxgyxfyxh,,,,

,,,∗∗=′

∗=

( ) 2

2

2, σx

eyxg−

=

σσ 2=′ E.G.M. Petrakis Filtering 35

( ) ( )( )

( )22

2

22

2

2

2

2

2

2

2

2

2222

2

22

22

22

σσ

ξ

σ

ξ

σ

ξ

σξ

σξ

σπξ

ξ

ξ

xx

xx

x

ede

dee

deexgxg

−∞+

∞−

+

∞+

∞−

+

+∞

∞−

−−−

==

==

==∗ E.G.M. Petrakis Filtering 36

Observations

• Filter an image with a large Gaussian – equivalently, filter the image twice with a

Gaussian with small σ– filtering twice with a m x n Gaussian is

equivalent to filtering with a (n + m - 1) x (n + m - 1) filter

– this implies a significant reduction in computations

σ2 E.G.M. Petrakis Filtering 37

Gaussian Separability

( ) ( ) ( )

( ) ( )

( )( ) =−−=

=−−=

=∗=

∑∑

∑∑

= =

+−

= =

m

k

n

l

lk

m

k

n

l

ljkife

ljkiflkg

jigjifjih

1 1

2

1 1

,

,,

,,,

2

22

σ E.G.M. Petrakis Filtering 38

( )

( )∑

∑ ∑

=

= =

−−

−′=

=

−−=

m

k

k

m

k

h

n

l

lk

jkihe

ljkifee

1

2

1

'

1

22

,

,

2

2

2

2

2

2

σ

σσ

444 3444 21

1-D Gaussian horizontally

1-D Gaussian vertically

• The order of convolutions can be reversed E.G.M. Petrakis Filtering 39

• An example of the separability of Gaussian convolution– left: convolution with vertical mask– right: convolution with horizontal mask E.G.M. Petrakis Filtering 40

Gaussian Separability

• Filtering with a 2D Gaussian can be implemented using two 1D Gaussianhorizontal filters as follows:– first filter with an 1D Gaussian– take the transpose of the result– convolve again with the same filter– transpose the result

• Filtering with two 1D Gausians is faster !! E.G.M. Petrakis Filtering 41

a. Noisy imageb. Convolution with