Top Banner
Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala
29

Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Dec 19, 2015

Download

Documents

Myrtle Hopkins
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Lecture 2: Filtering

CS4670/5670: Computer VisionKavita Bala

Page 2: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Announcements

• PA 1 will be out early next week (Monday)– due in 2 weeks– to be done in groups of two – please form your

groups ASAP• We will grade in demo sessions

Page 3: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Linear filtering• One simple version: linear filtering

– Replace each pixel by a linear combination (a weighted sum) of its neighbors

– Simple, but powerful– Cross-correlation, convolution

• The prescription for the linear combination is called the “kernel” (or “mask”, “filter”)

0.5

0.5 00

10

0 00

kernel

8

Modified image data

Source: L. Zhang

Local image data

6 14

1 81

5 310

Page 4: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Filter Properties

• Linearity– Weighted sum of original pixel values– Use same set of weights at each point– S[f + g] = S[f] + S[g] – S[p f + q g] = p S[f] + q S[g]

• Shift-invariance– If f[m,n] g[m,n], then f[m-p,n-q] g[m-p, n-q] – The operator behaves the same everywhere

S S

Page 5: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Cross-correlation

This is called a cross-correlation operation:

Let be the image, be the kernel (of size 2k+1 x 2k+1), and be the output image

• Can think of as a “dot product” between local neighborhood and kernel for each pixel

Page 6: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Convolution• Same as cross-correlation, except that the

kernel is “flipped” (horizontally and vertically)

• Convolution is commutative and associative

This is called a convolution operation:

Page 7: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Convolution

Adapted from F. Durand

Page 8: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Pseudo-code

CS 4620 and 5625 cover topic in detail

Page 9: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Linear filters: examples

000

001

000

Original Shifted leftBy 1 pixel

Source: D. Lowe

* =

Page 10: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Convolution

• Point spread function, impulse response function

PSF of Hubble Telescope

Page 11: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

http://aetherforce.com/wp-content/uploads/2013/10/8707342.jpg

Page 12: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Smoothing with box filter

Source: D. Forsyth111

111

111

Page 13: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Gaussian Kernel

Source: C. Rasmussen

Page 14: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Gaussian Kernel

0.003 0.013 0.022 0.013 0.0030.013 0.059 0.097 0.059 0.0130.022 0.097 0.159 0.097 0.0220.013 0.059 0.097 0.059 0.0130.003 0.013 0.022 0.013 0.003

5 x 5, = 1

Source: C. Rasmussen

Page 15: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Gaussian filters

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

Page 16: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Mean vs. Gaussian filtering

Page 17: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Detour: Fourier Analysis• Every signal has some frequency• Fourier analysis finds frequencies of a signal– Sum of sine/cosine waves

Source: Foley, van Dam

Page 18: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Detour: Fourier Analysis

Source: Foley, van Dam

Page 19: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Source: Foley, van Dam

Page 20: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Convolution is special

• Convolution in image space– Multiplication in Fourier space

• Box filter -> sinc in Fourier space• Gaussian filter -> Gaussian in Fourier space

Page 21: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Low pass filtering

Source: Foley, van Dam

Page 22: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Gaussian filter• Removes “high-frequency” components from

the image (low-pass filter)• Convolution with self is another Gaussian

– Convolving twice with Gaussian kernel of width = convolving once with kernel of width

Source: K. Grauman

* =

Page 23: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Source: Foley, van Dam

Page 24: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Sharpening• What does blurring take away?

original smoothed (5x5)

detail

=

sharpened

=

Let’s add it back:

original detail

+ α

Source: S. Lazebnik

Page 25: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Linear filters: examples

Original

111

111

111

000

020

000

-

Sharpening filter (accentuates edges)

Source: D. Lowe

=*

Page 26: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Sharpening

Source: D. Lowe

Page 27: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Sharpen filter

Gaussianscaled impulseLaplacian of Gaussian

imageblurredimage unit impulse

(identity)

Page 28: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

Sharpen filter

unfiltered

filtered

Page 29: Lecture 2: Filtering CS4670/5670: Computer Vision Kavita Bala.

“Optical” Convolution

Source: http://lullaby.homepage.dk/diy-camera/bokeh.html

Bokeh: Blur in out-of-focus regions of an image.

Camera shake

*=Source: Fergus, et al. “Removing Camera Shake from a Single Photograph”, SIGGRAPH 2006