spatial filtering (chapter 3) cs474/674 - prof. bebis

45
Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Upload: samara-pickren

Post on 14-Dec-2015

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Spatial Filtering (Chapter 3)

CS474/674 - Prof. Bebis

Page 2: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Spatial Filtering Methods (or Mask Processing Methods)

output image

Page 3: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Spatial Filtering

• The word “filtering” has been borrowed from the frequency domain.

• Filters are classified as:– Low-pass (i.e., preserve low frequencies)

– High-pass (i.e., preserve high frequencies)

– Band-pass (i.e., preserve frequencies within a band)

– Band-reject (i.e., reject frequencies within a band)

Page 4: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Spatial Filtering (cont’d)

• Spatial filtering is defined by:(1) A neighborhood

(2) An operation that is performed on the pixels inside the neighborhood

output image

Page 5: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Spatial Filtering - Neighborhood

• Typically, the neighborhood is rectangular and its size is much smaller than that of f(x,y)

- e.g., 3x3 or 5x5

Page 6: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Spatial filtering - Operation

1 1

1 1

( , ) ( , ) ( , )s t

g x y w s t f x s y t

Assume the origin of themask is the center of themask.

/2 /2

/2 /2

( , ) ( , ) ( , )K K

s K t K

g x y w s t f x s y t

for a K x K mask:

for a 3 x 3 mask:

Page 7: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Spatial filtering - Operation

• A filtered image is generated as the center of the mask moves to every pixel in the input image.

output image

Page 8: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Handling Pixels Close to Boundaries

pad with zeroes

or

0 0 0 ……………………….0

0 0 0 ……

……

……

……

….0

Page 9: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Linear vs Non-LinearSpatial Filtering Methods

• A filtering method is linear when the output is a weighted sum of the input pixels.

• Methods that do not satisfy the above property are called non-linear.– e.g.,

Page 10: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Linear Spatial Filtering Methods

• Two main linear spatial filtering methods:– Correlation

– Convolution

Page 11: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Correlation

OutputImage

w(i,j)

f(i,j)

/2 /2

/2 /2

( , ) ( , ) ( , ) ( , ) ( , )K K

s K t K

g x y w x y f x y w s t f x s y t

g(i,j)

Page 12: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Correlation (cont’d)

Often used in applications where we need to measure the similarity between images or parts of images(e.g., pattern matching).

Page 13: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Convolution

• Similar to correlation except that the mask is first flipped both horizontally and vertically.

Note: if w(x,y) is symmetric, that is w(x,y)=w(-x,-y), then convolution is equivalent to correlation!

/2 /2

/2 /2

( , ) ( , ) ( , ) ( , ) ( , )K K

s K t K

g x y w x y f x y w s t f x s y t

Page 14: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Example

Correlation:

Convolution:

Page 15: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

How do we choose the elements of a mask?

• Typically, by sampling certain functions.

Gaussian1st derivativeof Gaussian

2nd derivativeof Gaussian

Page 16: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Filters

• Smoothing (i.e., low-pass filters)– Reduce noise and eliminate small details.

– The elements of the mask must be positive.

– Sum of mask elements is 1 (after normalization)

Gaussian

Page 17: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Filters (cont’d)

• Sharpening (i.e., high-pass filters)– Highlight fine detail or enhance detail that has been blurred.

– The elements of the mask contain both positive and negative weights.

– Sum of the mask weights is 0 (after normalization)

1st derivativeof Gaussian

2nd derivativeof Gaussian

Page 18: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing Filters: Averaging(Low-pass filtering)

Page 19: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing Filters: Averaging (cont’d)• Mask size determines the degree of smoothing and loss of detail.

3x3 5x5 7x7

15x15 25x25

original

Page 20: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing Filters: Averaging (cont’d)

15 x 15 averaging image thresholding

Example: extract, largest, brightest objects

Page 21: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing filters: Gaussian

• The weights are samples of the Gaussian function

mask size isa function of σ :

σ = 1.4

Page 22: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing filters: Gaussian (cont’d)

• σ controls the amount of smoothing

• As σ increases, more samples must be obtained to represent

the Gaussian function accurately.

σ = 3

Page 23: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing filters: Gaussian (cont’d)

Page 24: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Averaging vs Gaussian Smoothing

Averaging

Gaussian

Page 25: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing Filters: Median Filtering(non-linear)

• Very effective for removing “salt and pepper” noise (i.e., random occurrences of black and white pixels).

averagingmedian filtering

Page 26: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Smoothing Filters: Median Filtering (cont’d)

• Replace each pixel by the median in a neighborhood around the pixel.

Page 27: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters (High Pass filtering)

• Useful for emphasizing transitions in image intensity (e.g., edges).

Page 28: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters (cont’d)

• Note that the response of high-pass filtering might be negative.

• Values must be re-mapped to [0, 255]

sharpened imagesoriginal image

Page 29: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Unsharp Masking

• Obtain a sharp image by subtracting a lowpass filtered (i.e., smoothed) image from the original image:

- =

Page 30: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: High Boost

• Image sharpening emphasizes edges but details (i.e., low frequency components) might be lost.

• High boost filter: amplify input image, then subtract a lowpass image.

(A-1) + =

Page 31: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: High Boost (cont’d)

• If A=1, we get a high pass filter

• If A>1, part of the original image is added back to the high pass filtered image.

Page 32: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: High Boost (cont’d)

A=1.4 A=1.9

Page 33: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Derivatives

• Taking the derivative of an image results in sharpening the image.

• The derivative of an image can be computed using the gradient.

Page 34: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Derivatives (cont’d)

• The gradient is a vector which has magnitude and direction:

| | | |f f

x y

or

(approximation)

Page 35: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Derivatives (cont’d)

• Magnitude: provides information about edge strength.

• Direction: perpendicular to the direction of the edge.

Page 36: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Gradient Computation

• Approximate gradient using finite differences:

sensitive to horizontal edges

sensitive to vertical edges

Δx

Page 37: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Gradient Computation (cont’d)

Page 38: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Example

f

x

f

y

Page 39: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Gradient Computation (cont’d)

• We can implement and using masks:

• Example: approximate gradient at z5

(x+1/2,y)

(x,y+1/2)*

*

good approximationat (x+1/2,y)

good approximationat (x,y+1/2)

Page 40: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Gradient Computation (cont’d)

• A different approximation of the gradient:

•We can implement and using the following masks:

*

(x+1/2,y+1/2)

good approximation

Page 41: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Gradient Computation (cont’d)

• Example: approximate gradient at z5

• Other approximations

Sobel

Page 42: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Example

f

y

f

x

Page 43: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Laplacian

The Laplacian (2nd derivative) is defined as:

(dot product)

Approximatederivatives:

Page 44: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Laplacian (cont’d)

Laplacian Mask

detect zero-crossings

Page 45: Spatial Filtering (Chapter 3) CS474/674 - Prof. Bebis

Sharpening Filters: Laplacian (cont’d)

Laplacian Sobel