Lec01 Filter
Lec01 Filter
Reading
• Szeliski, Chapter 3.1-3.3
What is an image?
What is each part of an image?
• Pixel -> picture element
‘138’
y
I(x,y)
x
Image as a 2D sampling of signal
• Signal: function depending on some variable with
physical meaning.
Danny Alexander
Sampling in 1D
Danny Alexander
Sampling in 2D
• Sampling in 2D
takes a function
and returns a
matrix.
Danny Alexander
Grayscale Digital Image
• Pixel -> picture element
‘127’
y
I(x,y)
x
Grayscale Digital Image
Brightness
or intensity
x y
Danny Alexander
Image Histogram
Image Histogram
Quantization
Quantization Effects – Radiometric
Resolution
Digital Camera
255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 20 0 255 255 255 255 255 255 255
=
255 255 75 95 95 75 255 255 255 255 255 255
255 255 96 127 145 175 255 255 255 255 255 255
255 255 127 145 175 175 175 255 255 255 255 255
255 255 127 145 200 200 175 175 95 255 255 255
255 255 127 145 200 200 175 175 95 47 255 255
255 255 127 145 145 175 127 127 95 47 255 255
255 255 255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255 255 255
f (x, y)
10 5 3 Some function
4 5 1 7
1 1 7
Source: L. Zhang
Linear filtering
• One simple version of filtering: linear filtering (cross-
correlation, convolution)
– Replace each pixel by a linear combination (a weighted
sum) of its neighbors
• The prescription for the linear combination is called the
“kernel” (or “mask”, “filter”)
10 5 3 0 0 0
4 6 1 0 0. 0 8
1 1 8 0 5
1 0.5
[ [
data [ ]
Cross-correlation
Let be the image, be the kernel (of
size 2k+1 x 2k+1), and be the
output image
h
Convolution
• Same as cross-correlation, except that the
kernel is “flipped” (horizontally and vertically)
f
Convolution
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10
0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
=
0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30
*
1 1 1
1 1 1 0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
1 1 1
0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Mean filtering/Moving average
Mean filtering/Moving average
Mean filtering/Moving average
Mean filtering/Moving average
Mean filtering/Moving average
Mean filtering/Moving average
Linear filters: examples
0 0 0
* 0
0
1
0
0
0
Original
Source: D. Lowe
What image operation does filtering
with this kernel perform?
([0 0 0; 0 1 0; 0 0 0])
0 0 0
=
* 0
0
1
0
0
0
Source: D. Lowe
Linear filters: examples
0 0 0
* 1
0
0
0
0
0
Original
Source: D. Lowe
What image operation does filtering
with this kernel perform? ([0 0 0; 1 0
0; 0 0 0])
0 0 0
=
* 1
0
0
0
0
0
Source: D. Lowe
Linear filters: examples
1 1 1
=
* 1
1
1
1
1
1
Source: D. Lowe
Linear filters: examples
-
0 0 0 1 1 1
* 0
0
2
0
0
0
1 1 1
1 1 1
=
Sharpening
Original
filter
(accentuates
edges)
Source: D. Lowe
Sharpening
Source: D. Lowe
Linear filters: examples
1 0 -1
2 0 -2
1 0 -1
Sobel
Vertical Edge
(absolute value)
David Lowe
Linear filters: examples
1 0 -1
2 0 -2
1 0 -1
Sobel
Vertical Edge
(absolute value)
David Lowe
Linear filters: examples
1 2 1
0 0 0
-1 -2 -1
Sobel
Horizontal Edge
(absolute value)
David Lowe
Smoothing with box filter revisited
Source: D. Forsyth
Gaussian kernel
Source: C. Rasmussen
Gaussian filters
* =
– Convolving twice with Gaussian kernel of width
= convolving once with kernel of
width
Source: K. Grauman
Sharpening revisited
• What does blurring take away?
– =
original smoothed (5x5) detail
(This “detail extraction” operation
Let’s add it back: is also called a high-pass
filter)
+α =
original detail sharpened
Photo credit: https://www.flickr.com/photos/geezaweezer/16089096376/
Sharpen filter
+
blurred
image unit impulse
image
(identity kernel
with single 1 in
center, zeros
elsewhere)
unfiltered
filtered
“Optical” convolution
Camera
shake
= *
Source: Fergus, et al. “Removing Camera Shake from a Single Photograph”, SIGGRAPH 2006
Source: https://www.diyphotography.net/diy_create_your_own_bokeh/
Filters: Thresholding
Linear filters
• Can thresholding be implemented with a linear
filter?
Can thresholding be
implemented with a linear
filter?