applications of image filtersdhoiem.web.engr.illinois.edu/courses/vision... · gaussian smoothing...

59
Applications of Image Filters Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 02/04/10

Upload: others

Post on 26-Sep-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Applications of Image Filters

Computer Vision

CS 543 / ECE 549 

University of Illinois

Derek Hoiem

02/04/10

Page 2: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Credit: S. Seitz

],[],[],[,

lnkmglkfnmhlk

++=∑

[.,.]h[.,.]f

Review: Image filtering

111

111

111

],[g ⋅⋅

Page 3: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 10

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

],[],[],[,

lnkmglkfnmhlk

++=∑

[.,.]h[.,.]f

Image filtering

111

111

111

],[g ⋅⋅

Credit: S. Seitz

Page 4: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 10 20

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

],[],[],[,

lnkmglkfnmhlk

++=∑

[.,.]h[.,.]f

Image filtering

111

111

111

],[g ⋅⋅

Credit: S. Seitz

Page 5: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Filtering in spatial domain-101

-202

-101

* =

Page 6: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Filtering in frequency domain

FFT

FFT

Inverse FFT

Page 7: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Sharpening revisited• What does blurring take away?

original smoothed (5x5)

detail

=

sharpened

=

Let’s add it back:

original detail

+ α

Page 8: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Application: Hybrid Images

• A. Oliva, A. Torralba, P.G. Schyns, “Hybrid Images,” SIGGRAPH 2006

Page 9: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Application: Hybrid Images

• A. Oliva, A. Torralba, P.G. Schyns, “Hybrid Images,” SIGGRAPH 2006

Page 10: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Today’s class

• How to use filters for– Matching

– Denoising

– Anti‐aliasing

• Image representation with pyramids

• Texture– What is it?

– How to represent it?

Page 11: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Matching with filters

• Goal: find       in image

Page 12: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Matching with filters

• Goal: find       in image

• Method 1: SSD

Input 1- sqrt(SSD) Threshold at 0.8

Page 13: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Matching with filters

• Goal: find       in image

• Method 1: SSD

• Method 2: Normalized cross‐correlation

Input Normalized X-Correlation Threshold at 0.5

Page 14: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Noise

Gaussian Additive Noise

+ =

Noisy Image

Page 15: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Gaussian noise

• Mathematical model: sum of many independent factors

• Assumption: independent, zero‐mean noise

Source: M. Hebert

Page 16: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Noise

• Salt and pepper noise: contains random occurrences of black and white pixels

• Impulse noise: contains random occurrences of white pixels

• Gaussian noise: variations in intensity drawn from a Gaussian normal distribution

Original

Gaussian noise

Salt and pepper noise

Impulse noise

Source: S. Seitz

Page 17: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Denoising

Additive Gaussian Noise

Gaussian Filter

Page 18: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Smoothing with larger standard deviations suppresses noise, but also blurs the image

Reducing Gaussian noise

Source: S. Lazebnik

Page 19: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Reducing salt‐and‐pepper noise by Gaussian smoothing

3x3 5x5 7x7

Page 20: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Alternative idea: Median filtering

• A median filter operates over a window by selecting the median intensity in the window

• Is median filtering linear?Source: K. Grauman

Page 21: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Median filter• What advantage does median filtering have over Gaussian filtering?– Robustness to outliers

Source: K. Grauman

Page 22: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Median filterSalt-and-pepper noise Median filtered

Source: M. Hebert

• MATLAB: medfilt2(image, [h w])

Page 23: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Median vs. Gaussian filtering3x3 5x5 7x7

Gaussian

Median

Page 24: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Throw away every other row and column to create a 1/2 size image

Subsampling by a factor of 2

Page 25: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

• 1D example (sinewave):

Source: S. Marschner

Aliasing problem

Page 26: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Source: S. Marschner

• 1D example (sinewave):

Aliasing problem

Page 27: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

• Sub‐sampling may be dangerous….

• Characteristic errors may appear: – “Wagon wheels rolling the wrong way in movies”

– “Checkerboards disintegrate in ray tracing”

– “Striped shirts look funny on color television”

Source: D. Forsyth

Aliasing problem

Page 28: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Aliasing in video

Slide by Steve Seitz

Page 29: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Source: A. Efros

Aliasing in graphics

Page 30: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Sampling and aliasing

Page 31: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

• When sampling a signal at discrete intervals, the sampling frequency must be ≥ 2 × fmax; 

• fmax = max frequency of the input signal.

• This will allows to reconstruct the original perfectly from the sampled version

good

bad

v v v

Nyquist‐Shannon Sampling Theorem

Page 32: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Anti‐aliasing

Solutions:

• Sample more often

• Get rid of all frequencies that are greater than half the new sampling frequency– Will lose information

– But it’s better than aliasing

– Apply a smoothing filter

Page 33: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Algorithm for downsampling by factor of 2

1. Start with image(h, w)

2. Apply low‐pass filterim_blur = imfilter(image, fspecial(‘gaussian’, 7, 1))

3. Sample every other pixelim_small = im_blur(1:2:end, 1:2:end);

Page 34: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Anti‐aliasing

Forsyth and Ponce 2002

Page 35: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Subsampling without pre‐filtering

1/4 (2x zoom) 1/8 (4x zoom)1/2

Slide by Steve Seitz

Page 36: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Subsampling with Gaussian pre‐filtering

G 1/4 G 1/8Gaussian 1/2

Slide by Steve Seitz

Page 37: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Gaussian pyramid

Source: Forsyth

Page 38: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Laplacian filter

Gaussianunit impulse

Laplacian of Gaussian

Source: Lazebnik

Page 39: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Laplacian pyramid

Source: Forsyth

Page 40: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Computing Gaussian/Laplacian Pyramid

http://sepwww.stanford.edu/~morgan/texturematch/paper_html/node3.html

Can we reconstruct the original from the laplacian pyramid?

Page 41: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Related idea: 2d wavelets

Page 42: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

2d Wavelets

Matlab: wavemenu

Page 43: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Image representation

• Pixels: great for spatial resolution, poor access to frequency

• Fourier transform: great for frequency, not for spatial info

• Pyramids/wavelets: balance between spatial and frequency information

Page 44: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Major uses of image pyramids

• Compression

• Object detection– Scale search– Features

• Detecting stable interest points 

• Registration– Course‐to‐fine

Page 45: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Texture

Source: Forsyth

Page 46: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Texture and Material

http://www-cvr.ai.uiuc.edu/ponce_grp/data/texture_database/samples/

Page 47: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Texture and Orientation

http://www-cvr.ai.uiuc.edu/ponce_grp/data/texture_database/samples/

Page 48: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Texture and Scale

http://www-cvr.ai.uiuc.edu/ponce_grp/data/texture_database/samples/

Page 49: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

What is texture?

• Regular or stochastic patterns caused by bumps, grooves, and/or markings

Page 50: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

How can we represent texture?

• Measure frequencies at various orientations and scales

Page 51: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Overcomplete representation: filter banks

LM Filter Bank

Code for filter banks: www.robots.ox.ac.uk/~vgg/research/texclass/filters.html

Page 52: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Filter banks

• Process image with each filter and keep responses (or squared/abs responses)

Page 53: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Representing texture

• Idea 1: take simple statistics (e.g., mean, std) of various absolute filter responses

Page 54: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Can you match the texture to the response?

Mean abs responses

FiltersA

B

C

1

2

3

Page 55: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Representing texture by mean abs response

Mean abs responses

Filters

Page 56: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Representing texture• Idea 2: take vectors of filter responses at each pixel and 

cluster them, then take histograms (more on in coming weeks)

Page 57: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Things to remember

• When matching using a filter, normalized cross correlation is preferred

• Use Gaussian or median filter for denoising

• Beware of aliasing – use lowpass filter to downsample

• Laplacian pyramids and wavelets provide spatial/frequency information

• Filter banks provide overcomplete representation, good for modeling/recognizing texture

Page 58: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Next class

• Edges and lines

Page 59: Applications of Image Filtersdhoiem.web.engr.illinois.edu/courses/vision... · Gaussian smoothing 3x3. 5x5. 7x7. Alternative idea: Median filtering • A ... Major uses of image pyramids

Questions