Image Filtering Edge Detection
Image Filtering Edge Detection
Reading:
Chapter 7 and 8, F&P
Linear Functions
Simplest: linear filtering.
Replace each pixel by a linear combination of its
neighbors.
The prescription for the linear combination is
called the convolution kernel.
1
Properties in more detail
Commutative: a * b = b * a
Conceptually no difference between filter and signal
Associative: a * (b * c) = (a * b) * c
Often apply several filters one after another: (((a * b1) * b2) * b3)
This is equivalent to applying one filter: a * (b1 * b2 * b3)
Distributes over addition: a * (b + c) = (a * b) + (a * c)
Scalars factor out: ka * b = a * kb = k (a * b)
Identity: unit impulse e = [, 0, 0, 1, 0, 0, ],
a*e=a
2
Yucky details
What is the size of the output?
MATLAB: filter2(g, I, shape)
shape = full: output size is sum of sizes of I and g
shape = same: output size is same as I
shape = valid:output size is of difference sizes for I & g
full same valid
g g g g
g g
I I I
g g g
g
g g
3
Linear filtering (warm-up slide) Linear filtering (warm-up slide)
coefficient
coefficient
1.0
? 1.0
0 0
Pixel offset Pixel offset
original original Filtered
0 0 0 (no change)
0 1 0
0 0 0
coefficient
1.0 1.0
0
? 0
Pixel offset Pixel offset
original original shifted
0 0 0
0 0 1
0 0 0
coefficient
0.3
0
? 0.3
0
Pixel offset Pixel offset
original original Blurred (filter
1 1 1 applied in both
Box filter: 1 1 1 dimensions).
1 1 1
4
Blur examples Blur examples
coefficient
coefficient
8 2.4 8 2.4
impulse impulse
0.3 0.3
0 0
original Pixel offset filtered original Pixel offset filtered
coefficient
8 8
edge 4 4
0.3
0
original Pixel offset filtered
Smoothing with box filter revisited Smoothing with box filter revisited
Smoothing with an average actually doesnt Smoothing with an average actually doesnt compare at
compare at all well with a defocused lens all well with a defocused lens
Most obvious difference is that a single point of Most obvious difference is that a single point of light
light viewed in a defocused lens looks like a fuzzy viewed in a defocused lens looks like a fuzzy blob; but
blob; but the averaging process would give a little
square the averaging process would give a little square
Better idea: to eliminate edge effects, weight
contribution of neighborhood pixels according to their
closeness to the center, like so:
5 x 5, = 1
5
Gaussian filtering Example: Smoothing with a
A Gaussian kernel gives less weight to pixels further Gaussian
from the center of the window
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 1 2 1
0 0 0 90 90 90 90 90 0 0 2 4 2
0 0 0 90 0 90 90 90 0 0 1 2 1
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
Source: D. Lowe
6
Review: Linear filtering Noise
What are the defining mathematical properties Salt and pepper
of a convolution? noise: contains
random occurrences
What is the difference between blurring with a of black and white
box filter and blurring with a Gaussian? pixels
Impulse noise:
What happens when we convolve a Gaussian Original Salt and pepper noise contains random
with another Gaussian? occurrences of white
What is separability? pixels
Gaussian noise:
How does separability affect computational variations in intensity
complexity? drawn from a
Gaussian normal
distribution
Impulse noise Gaussian noise
Source: S. Seitz
7
Median filter Median filter
Salt-and-pepper noise Median filtered
What advantage does median filtering have
over Gaussian filtering?
Robustness to outliers
2.0
Gaussian
1.0
0 0
?
original
Median
2.0 2.0
1.0
0 0 0
0.33
0
?
original Filtered original
(no change)
8
(Remember blurring) Sharpening
2.0
coefficient
0.3 0.33
0 0
0
Pixel offset
original Sharpened
original Blurred (filter
original
applied in both
dimensions).
1.7
11.2
coefficient
8 8
-0.25
-0.3
original Sharpened
(differences are
accentuated; constant
areas are left untouched).
Sharpening Sharpening
0 0 0 1 1 1 0 0 0 1 1 1
0 2 0
0 0 0
- 1 1 1
1 1 1
? 0 2 0
0 0 0
- 1 1 1
1 1 1
9
Sharpening Unsharp mask filter
I + ( I I g ) = ( 1 + ) I I g = I (( 1 + ) e g )
before after
unit impulse
Gaussian Laplacian of Gaussian
illumination discontinuity
10
Image gradient Differentiation and convolution
The gradient of an image: Recall, for 2D We could
function, f(x,y): approximate this as
The gradient points in the direction of most rapid change in intensity f f (x + , y) f (x, y ) f f (xn+1 , y ) f (xn , y)
= lim
x 0 x x
11
Effects of noise Solution: smooth first
Finite difference filters respond strongly to noise
Image noise results in pixels that look very different
from their neighbors
Generally, the larger the noise the stronger the
response
What is to be done?
Smoothing the image should help, by forcing pixels
different to their neighbors (=noise pixels?) to look
more like neighbors
* [1 -1] =
This saves us one operation:
d
g
dx
d
f g
dx
Source: S. Seitz
12
Tradeoff between smoothing and Implementation issues
localization
g = fspecial('gaussian',15,2);
imagesc(g)
surfl(g)
gclown = conv2(clown,g,'same');
imagesc(conv2(clown,[-1 1],'same'));
imagesc(conv2(gclown,[-1 1],'same'));
dx = conv2(g,[-1 1],'same');
imagesc(conv2(clown,dx,'same'));
lg = fspecial('log',15,2);
lclown = conv2(clown,lg,'same');
imagesc(lclown) We wish to mark points along the curve where the magnitude is biggest.
We can do this by looking for a maximum along a slice normal to the
imagesc(clown + .2*lclown) curve (non-maximum suppression). These points should form a curve.
There are then two algorithmic issues: at which point is the maximum,
and where is the next one?
Source: D. Forsyth
13
Non-maximum suppression Predicting the next edge point
At q, we have a Assume the marked
maximum if the point is an edge point.
value is larger Then we construct the
than those at tangent to the edge
both p and at r. curve (which is normal
Interpolate to to the gradient at that
get these point) and use this to
values. predict the next points
(here either r or s).
14
The Canny edge detector The Canny edge detector
original image
15