image filtering

COS 351 - Computer Vision

three views of filtering

  1. image filters in spatial domain
    • filter is a mathematical operation of a grid of numbers
    • smoothing, sharpening, measuring texture
  2. image filters in the frequency domain
    • filtering is a way to modify the frequencies of images
    • denoising, sampling, image compression
  3. templates and image pyramids
    • filtering is a way to match a template to the image
    • detection, coarse-to-fine registration

image filtering

Image filtering: compute function of local neighborhood at each position

Really important!

example: box filter




\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

image filtering

\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

\[h[m,n] = \sum_{k,l} g[k,l]\ \ f[m+k,n+l]\]

box filter

What does it do?



\[ \texttt{g[} \cdot, \cdot \texttt{]} = \frac{1}{9} \]
111
111
111

smoothing with box filter



practice with linear filters

original
?
000
010
000

practice with linear filters

original
identity (no change)
000
010
000

practice with linear filters

original
?
000
001
000

practice with linear filters

original
shifted left by 1 pixel
000
001
000

practice with linear filters

original
?
000
020
000
\[- \frac{1}{9}\]
111
111
111
[ note that filter sums to 1 ]

practice with linear filters

original
sharpened
000
020
000
\[- \frac{1}{9}\]
111
111
111
[ note that filter sums to 1 ]

sharpening

Sharpening filter accentuates differences with local average

-0.111-0.111-0.111
-0.1111.888-0.111
-0.111-0.111-0.111

other filters: sobel

Sobel filter finds vertical and horizontal edges

10-1
20-2
10-1

other filters: sobel

Sobel filter finds vertical and horizontal edges

121
000
-1-2-1

filtering vs. convolution

With kernel g and image f

2D filtering

2D convolution

key properties of linear filters

Any linear, shift-invariant operator can be represented as a convolution

key properties of linear filters

important filter: gaussian

Weight contributions of neighboring pixels by nearness

\[G_\sigma = \frac{1}{2\pi\sigma^2} e^{-\frac{(x^2+y^2)}{2\sigma^2}}\] \[\]
0.0030.0130.0220.0130.003
0.0130.0590.0970.0590.013
0.0220.0970.1590.0970.022
0.0130.0590.0970.0590.013
0.0030.0130.0220.0130.003
\[ 5\times5, \sigma = 1\]

smoothing with box filter



smoothing with Gaussian filter



gaussian filters

separability of the gaussian filter

\[ \begin{array}{rl} G_\sigma(x,y) & = \frac{1}{2\pi\sigma^2} e^{-\frac{(x^2+y^2)}{2\sigma^2}} \\ & = \left( \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{x^2}{2\sigma^2}} \right) \left( \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{y^2}{2\sigma^2}} \right) \end{array} \]



The 2D Gaussian can be expressed as the product of two functions, one a function of \(x\) and the other a function of \(y\).

In this case, the two functions are the (identical) 1D Gaussian.

separability example

2D convolution (center location only)

121
242
121
\(*\)
233
355
446

separability example

2D convolution (center location only)

121
242
121
\(*\)
233
355
446


2D filter factors into a product of 1D filters

121
242
121
\(=\)
1
2
1
121

separability example

2D convolution (center location only)

\[ \Bigg( \]
1
2
1
121
\[ \Bigg) \] \(*\)
233
355
446

separability example

2D convolution (center location only)

Perform convolution along rows...

121
\(*\)
233
355
446
\( = \)
11
18
18

... then along remaining column.

1
2
1
\(*\)
11
18
18
\( = \)
65

separability

Why is separability useful in practice?

separability

Why is separability useful in practice?



Because it is faster!

practical matters

practical matters

practical matters

imfilter(f, g, 0);            % clip filter (black)
imfilter(f, g, 'circular');   % wrap around
imfilter(f, g, 'replicate');  % copy edge
imfilter(f, g, 'symmetric');  % reflect across edge
original
extend: clip
filter
crop

practical matters

imfilter(f, g, 0);            % clip filter (black)
imfilter(f, g, 'circular');   % wrap around
imfilter(f, g, 'replicate');  % copy edge
imfilter(f, g, 'symmetric');  % reflect across edge
original
extend: wrap
filter
crop

practical matters

imfilter(f, g, 0);            % clip filter (black)
imfilter(f, g, 'circular');   % wrap around
imfilter(f, g, 'replicate');  % copy edge
imfilter(f, g, 'symmetric');  % reflect across edge
original
extend: copy
filter
crop

practical matters

imfilter(f, g, 0);            % clip filter (black)
imfilter(f, g, 'circular');   % wrap around
imfilter(f, g, 'replicate');  % copy edge
imfilter(f, g, 'symmetric');  % reflect across edge
original
extend: reflect
filter
crop

practical matters

filter2(g, f, 'full');   % sum of sizes of f and g
filter2(g, f, 'same');   % same as f
filter2(g, f, 'valid');  % difference of sizes of f and g

median filters

comparison: salt and pepper noise

[ © 2006 Steve Marschner, Slide by Steve Seitz ]

assign01: hybrid images

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

top filter: Gaussian
bottom filter: Laplacian

take-home messages

practice questions

practice questions

  • Fill in the blanks, where * is filtering operator
    • _ = D * B
    • A = _ * _
    • F = D * _
    • _ = D * D

Laplacian of Gaussian

\[G_\sigma = \frac{1}{2\pi\sigma^2} e^{-\frac{(x^2+y^2)}{2\sigma^2}}\]

\[ LoG_\sigma(x,y) = - \frac{1}{\pi\sigma^4} \left( 1 - \frac{x^2+y^2}{2\sigma^2} \right) e^{-\frac{x^2+y^2}{2\sigma^2}}\]

loading...