image filtering cs485/685 computer vision prof. george bebis

42
Image Filtering CS485/685 Computer Vision Prof. George Bebis

Post on 19-Dec-2015

236 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Image Filtering

CS485/685 Computer Vision

Prof. George Bebis

Page 2: Image Filtering CS485/685 Computer Vision Prof. George Bebis

What is image filtering?

f(x,y) g(x,y)

filtering

filtering

Page 3: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Image Filtering Methods

• Spatial Domain

• Frequency Domain (i.e., uses Fourier Transform)

Page 4: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Spatial Domain Methods

f(x,y)

g(x,y)

g(x,y)

f(x,y)

Page 5: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Point Processing Methods

• Convert a given pixel value to a new pixel value based on some predefined function.

Page 6: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Point Processing Methods - Examples

Negative Contrast stretching

Thresholding

Histogram

Equalization

Page 7: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Area Processing Methods

• Need to define:(1) Area shape and size

(2) Operation

output image

Page 8: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Area Shape and Size

• •Area shape is typically defined using a rectangular mask.

• Area size is determined by mask size.

e.g., 3x3 or 5x5

• Mask size is an important parameter!

Page 9: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Operation

• Typically linear combinations of pixel values.– e.g., weight pixel values and add them

together.

• Different results can be obtained using different weights. – e.g., smoothing, sharpening, edge

detection).

mask

Page 10: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Example

0.50.5 00

0

0 00

mask

8

Modified image dataLocal image neighborhood

6 141 81

5 310

1

Page 11: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Common Linear Operations

• Correlation

• Convolution

Page 12: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Correlation

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

g(i,j)

h(i,j)

f(i,j)

filteredimage

n x n mask

Page 13: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Handling Pixels Close to Boundaries

pad with zeroes

or

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

0 0 0 ……

……

……

……

….0

wrap around

Page 14: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Correlation – Example

Page 15: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Geometric Interpretation of Correlation

• Suppose x and y are two n-dimensional vectors:

• The dot product of x with y is defined as:

• Correlation generalizes the notion of dot product

1 2 1 2( , ,..., ) ( , ,..., )n nx x x x y y y y

1 1 2 2. ... n nx y x y x y x y

. | || |cos( )x y x y using vectornotation:

x

y

θ

Page 16: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Geometric Interpretation of Correlation (cont’d)

cos(θ) measures the similarity between x and y

Normalized correlation (i.e., divide by lengths)

2 2

2 2

2 2 2 22 1/2 2 1/2

2 2 2 2

( , ) ( , )

( , )

[ ( , )] [ ( , )]

n n

n nk l

n n n n

n n n nk l k l

h k l f i k j l

N i j

h k l f i k j l

. | || |cos( ) cos( )| || |

x yx y x y or

x y

Page 17: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Normalized Correlation

• Measure the similarity between images or parts of images.

=

mask

Page 18: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Application: TV Remote Control

Page 19: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Application : TV Remote Control (cont’d)

Page 20: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Application : TV Remote Control (cont’d)

Page 21: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Application : TV Remote Control (cont’d)

Page 22: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Application : TV Remote Control (cont’d)

Page 23: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Application : TV Remote Control (cont’d)

Page 24: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Normalized Correlation (cont’d)

• Traditional correlation cannot handle changes due to:

• size• orientation • shape (e.g., deformable objects).

?

Page 25: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Convolution

• Same as correlation except that the mask is flipped, both horizontally and vertically.

h * f = f * h

Notation:

1 2 3

4 5 6

7 8 9

7 8 9

4 5 6

1 2 3

9 8 7

6 5 4

3 2 1

H V

2 2 2 2

2 2 2 2

( , ) ( , ) ( , ) ( , ) ( , )

n n n n

n n n nk l k l

g i j h k l f i k j l h i k j l f k l

For symmetric masks (i.e., h(i,j)=h(-i,-j)), convolution is equivalent to correlation!

Page 26: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Correlation/Convolution Examples

Correlation:

Convolution:

Page 27: Image Filtering CS485/685 Computer Vision Prof. George Bebis

How do we choose the mask weights?

• Depends on the application.

• Usually by sampling certain functions and their derivatives.

Gaussian1st derivativeof Gaussian

2nd derivativeof Gaussian

Good forimage smoothing

Good for image sharpening

Page 28: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Normalization of Mask Weights

• Sum of weights affects overall intensity of output image.

• Positive weights – Normalize them such that they sum to oneone.

• Both positive and negative weights– Should sum to zerozero (but not always)

1/9 1/16

Page 29: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Smoothing Using Averaging

• Idea: replace each pixel by the average of its neighbors.

• Useful for reducing noise and unimportant details.

•The size of the mask controls the amount of smoothing.

Page 30: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Smoothing Using Averaging (cont’d)

• Trade-off:Trade-off: noise vs blurring and loss of detail.

3x3 5x5 7x7

15x15 25x25

original

Page 31: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Gaussian Smoothing

• Idea: replace each pixel by a weighted average of its neighbors

• Mask weights are computed by sampling a Gaussian function

Note: weight values decrease with distance from mask center!

Page 32: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Gaussian Smoothing (cont’d)

mask size depends on σ :

• σ determines the degree of smoothing!σ=3

Page 33: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Gaussian Smoothing (cont’d)Gaussian(sigma, hSize, h)float sigma, *h;int hSize;{ int i; float cst, tssq, x, sum;

cst = 1./(sigma*sqrt(2.0*PI)) ; tssq = 1./(2*sigma*sigma) ;

for(i=0; i<hSize; i++) { x=(float)(i-hSize/2); h[i]=(cst*exp(-(x*x*tssq))) ; } // normalize sum=0.0; for(i=0;i<hSize;i++) sum += h[i]; for(i=0;i<hSize;i++) h[i] /= sum;}

halfSize=(int)(2.5*sigma);hSize=2*halfSize;if (hSize % 2 == 0) ++hSize; // odd size

2

2

2

)(

2

1)(

x

exp

Page 34: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Gaussian Smoothing - Example

= 30 pixels= 1 pixel = 5 pixels = 10 pixels

Page 35: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Averaging vs Gaussian Smoothing

Averaging

Gaussian

Page 36: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Properties of Gaussian

• Convolution with self is another Gaussian

• Special case: convolving two times with Gaussian kernel of width is equivalent to convolving once with kernel of width

* =

Page 37: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Properties of Gaussian (cont’d)• Separable kernel: a 2D Gaussian can be expressed as the product of two 1D Gaussians.

Page 38: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Properties of Gaussian (cont’d)

• 2D Gaussian convolution can be implemented more efficiently using 1D convolutions:

Page 39: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Properties of Gaussian (cont’d)

row get a new image Ir

Convolve each column of Ir with g

Page 40: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Example

2D convolution(center location only)

The filter factorsinto a product of 1D

filters:

Perform convolutionalong rows:

Followed by convolutionalong the remaining column:

*

*

=

=

O(n2)

O(2n)=O(n)

Page 41: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Image Sharpening

• Idea: compute intensity differences in local image regions.

• Useful for emphasizing transitions in intensity (e.g., in edge detection).

1st derivativeof Gaussian

Page 42: Image Filtering CS485/685 Computer Vision Prof. George Bebis

Example