08 spatial

26
1 Image Enhancement (Spatial Domain Filters) Spatial Domain Spatial Filtering (As opposed to frequency domain filter) For linear filters Foundation based on the convolution theorem g(x,y) = h(x,y)*f(x,y) G(u,v) = H(u,v)F(u,v) Goal is to either remove, or isolate frequencies in the image • Types – Linear – Non-linear

Upload: bily82

Post on 21-Dec-2015

216 views

Category:

Documents


1 download

DESCRIPTION

Spatial

TRANSCRIPT

Page 1: 08 Spatial

1

Image Enhancement(Spatial Domain Filters)

Spatial Domain• Spatial Filtering

– (As opposed to frequency domain filter)– For linear filters

• Foundation based on the convolution theorem– g(x,y) = h(x,y)*f(x,y)– G(u,v) = H(u,v)F(u,v)

• Goal is to either remove, or isolate frequencies in the image

• Types– Linear– Non-linear

Page 2: 08 Spatial

2

Response of a linear mask

R = w1z1 + w2z2 + w3z3 ... + w9z9

Where wi are mask coefficients and zi are pixelintensities.

• Neighborhood operators– Convolution

Spatial Filtering using a Mask

Response of a linear mask, R, 9

R = ( w1z1 + w2z2 + w3z3 ... + w9z9) = ∑ wizi1

f(x,y) is centered around “z5” so g(x,y) = R =filter_about*f(x,y)

z1 z2 z3z4 z5 z6z7 z8 z9

w1 w2 w3w4 w5 w6w7 w8 w9

Page 3: 08 Spatial

3

Smoothing Filters

• Smoothing Filters– blurring

• “pre-processing”– removal of small details before object extraction

– noise reduction• removal of noise in an image

• Often called “Low-Pass” Filters– Filter lets low-frequencies pass – Stops high-frequencies

Low-pass spatial filtering

Frequency Domain Spatial Domain

0 0

1

Page 4: 08 Spatial

4

Low-pass spatial filtering

w1 w2 w3w4 w5 w6w7 w8 w9

•We can build a gaussian filter

•But, only requirement fora low-pass filter is that wi be positive

•Note, that the result can belarger than the valid output range(L-1)

•Can pre-scale the filter

scale_factor = (Σ wi )-1

Low-pass spatial filter

1 1 11 1 11 1 1

1/9 *

Average Filter

1 1 11 1 11 1 1

1/9 *

Page 5: 08 Spatial

5

Extends to larger filters

1 1 11 1 11 1 1

1/9 *

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1 1 11 1 11 1 1

1/81 *

Example

original n=5 (nxn mask)

n=25 (nxn mask)n=15 (nxn mask)

Page 6: 08 Spatial

6

Other arrangements

1 1 1

1 2 1

1 1 1

Gaussian1111112321134311232111111

Weighted

Remember that the resulting gray-levelsmay be out of the range of the original image.

Isotropic Gaussian Filter

2

22

222

1),( σ

πσ

yx

eyxG+

−=

2D Gaussian distributionwith mean (0,0) and σ=1

Page 7: 08 Spatial

7

Computing a discrete gaussian mask

2

22

222

1),( σ

πσ

yx

eyxG+

−=

2 10

-1-2

210-1-2

Center the Mask at (0,0). So, a 5x5 mask would compute values by at:

Use G(x,y) to computevalues for mask.

Often scaled by Max-GrayLevel; ie, 255*G(x,y)

Computing a discrete gaussian mask2

22

222

1),( σ

πσ

yx

eyxG+

−=

Page 8: 08 Spatial

8

Linear vs. Non-linear• “Convolution”/Linear Filters

– Linear operation– Have corresponding frequency domain filter

• Non-linear Filters– Mask used to determine the proper substitution

of a “good” pixel value– Examine neighbors using various orderings

• Often use Rank or Order Statistics – Harder to interpret effect in frequency domain

Selected Smoothing

• (non-linear filter)• kth nearest neighbors

2 3 8

3 10

4 2 9

Find the kth nearest neighborsof (x,y) in a neighborhood nxn

k = 6nearest neighbors = {2,3,3,4,4,2}(x,y) = (2+3+3+4+4+2} * (1/6) = 3

Note: Straight Averaging would have equaled 5

pixel values about (x,y)window 3x3

4

Page 9: 08 Spatial

9

Max Homogeneity Smoothing• non-linear• Use 5 different windows with f(x,y)

included in all of them

Max Homogeneity Smoothing• Compute the gradient of each of these

“windows”• f(x,y) is the average of the window

with the smallest “variation”

Page 10: 08 Spatial

10

Max Homogeneity Smoothing• This filter is trying to find the

window that (x,y) is the most similar too.

?

Median Filter• Very popular non-linear filter• Find the median of the window• Preserves edges• Removes impulse noise, avoids excessive smoothing

2 3 8

3 10

4 2 9

4

pixel values about (x,y)window 3x3

neighbor sort = {2,2,3,3,4,4,8,9,10}

f(x,y) = median

Page 11: 08 Spatial

11

Example

Original Noisy Image

Low-Pass Filter Median Filter

Median Filter

• Often referred to as “de-speckle operation”

• It converges– That is, if you perform it over and over,

eventually the image will not change.

Page 12: 08 Spatial

12

Iterative Smoothing

• Local Averaging– Converges to an image with constant intensity

• Max-homogeneity and K-nearest– converges to a constant intensity or a piecewise

constant intensity• Median Filter

– Converges to an image invariant to the filter

Sharpening• Objective of sharpening

– Highlight fine detail in an image– Enhance detail that has been blurred– We can think of this as high-pass

filtering• Letting High Frequencies Pass• Removing Low Frequencies

Page 13: 08 Spatial

13

High-pass spatial filtering

Frequency Domain Spatial Domain

0 0

1

Basic hi-pass spatial filter

-1 -1 -1

-1 8 -1

-1 -1 -1

1/9 *

•Positive coefficients near its center

•Negative coefficients near the outerperiphery

•Note, the sum of the coefficients iszero

•Thus, when the mask is over anarea of constant intensity, the resultis zero

Page 14: 08 Spatial

14

Hi-pass filter

• The results may be negative

• You’ll need to scale and/or clip so that the gray levels of the result span [0, L-1]

• Don’t take absolute value of the response– Bad idea

Example

Original High-Pass

Page 15: 08 Spatial

15

High Pass filter

• Another way to think about the high pass filter:

– Highpass = Original – Lowpass

• Should be able to prove this using thelinear ‘R’ response equality and examplesof high-pass and low-pass filters

High Boost Filter

• High Boost = (A)(Original) – Lowpass= (A-1)(Original) + Original - Lowpass= (A-1)Original + Highpass

• Setting ‘A’ controls how much of the original image you would like to have show up in the result

• A=1 gives you the high-pass filter• A > 1 allows some of the low-frequencies back in

– Result, an image that looks more like the original with accents on the high-frequencies

Page 16: 08 Spatial

16

Constructing a High Boost Filter

-1 -1 -1

-1 w -1

-1 -1 -1

1/9 * w = 9A-1

Examples

Original A=1.1

A=1.15 A=1.2

Page 17: 08 Spatial

17

Derivative Filters

• Averaging pixels– blur– analogous to integration

• Differentiation– has the opposite effect of “blurring”– sharpens an image

First Order Derivatives • Gradient• Function of 2 variables x, y

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

∂∂

∂∂

=∇

yf

xf

f

x

y

Page 18: 08 Spatial

18

First Order Derivatives

• For each (x,y) you are storing two values:

• Often have two images to represent this• X-Gradient and Y-Gradient

– Can be computed independently

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

∂∂

∂∂

=∇

yf

xf

f

First Order Derivatives • X-Gradient and Y-Gradient

Original df/dy

df/dx f

Page 19: 08 Spatial

19

Gradient

• Gradient Magnitude

2/122

yf

xff)(mag

⎥⎥⎦

⎢⎢⎣

⎡⎟⎟⎠

⎞⎜⎜⎝

⎛∂∂

+⎟⎠⎞

⎜⎝⎛

∂∂

=∇=∇f

Gradient

• Gradient Angle/Direction

⎟⎠⎞

⎜⎝⎛

∂∂∂∂

=∇Ψ − xf/yf/tan)( 1f

Note: the angle is with respect to the “x” image axis

Page 20: 08 Spatial

20

Basic Derivative

• Consider the pixels

• f at z5 can be computed

z1 z2 z3z4 z5 z6z7 z8 z9

2/1285

265 ])()[( zzzzf −+−≈∇

Basic Derivative

• Consider the pixels

• f at z5 can be computed quicker

z1 z2 z3z4 z5 z6z7 z8 z9

|||| 8565 zzzzf −+−≈∇

Page 21: 08 Spatial

21

Basic Derivative

• f sometimes is computed using the “cross” difference

z1 z2 z3z4 z5 z6z7 z8 z9

|||| 9586 zzzzf −+−≈∇

Robert Gradient

• Roberts cross-gradient operators

-10

01

0-1

10

Even masks are awkward to implementResults in a phase-shift

Page 22: 08 Spatial

22

Odd Sized Masks

|)()(|

|)()(|

741963

321987

zzzzzz

zzzzzzf

++−++

+++−++≈∇

• Difference between first and third row (df/dy)

• Difference between first and third column(df/dx)

Odd sized mask

• Prewitt operator

111

000

-1-1-1

10-1

10-1

10-1

Page 23: 08 Spatial

23

Odd sized mask

• Sobel operator

• Weights closer neighbor a little more

121

000

-1-2-1

10-1

20-2

10-1

Requirements for Derivative Mask

• Measuring Change– df/dx = A*f(x,y) – B* f(x+1,y)– df/dy = A*f(x,y) – B*f(x,y+1)

• Derivative– Sum of the coefficients has to be zero

• This makes sure the derivative is zero in a region of constant intensity

Page 24: 08 Spatial

24

Example

Second Order Derivative

• Laplacian of a 2-D function f(x,y)• is a second-order derivative defined

as:

yf

xf f 2

2

2

22

∂∂

+∂∂

=∇

Page 25: 08 Spatial

25

Second Order Derivative • For a 3x3 region, the form most

encountered is:

• Requirements – Center pixel coefficient be positive– Outer coefficients be negative– Its a derivative, so sum of coefficient be zero

)(4 864252 zzzzzf +++−≈∇

Example of a Laplacian

• Typical Laplacian Operator(not used in practice)

0-10

-14-1

0-10

Page 26: 08 Spatial

26

Example

This is actually an example of a mask which is a Laplacian of a Gaussian (LoG Filter)See pp 582 of GW

Spatial Filters• Spatial Convolution

– We are convolving a function about each (x,y)– approximation of filters in the frequency domain

(at least for the linear filters . . non-linear is hard to analyze)– types

• Blurring, Smoothing, Sharpening, Derivatives• and the non-linear (Max Homogeneity, Kth Nearest, Median)

• Input gray-levels may be different than output levels– very common– May need to scale your image for visualization

• Filter coefficients do not have to be integers– Results are non-integer – use a float image