Conv Edges Template
Conv Edges Template
Source: K. Grauman
Partial derivatives of an image
∂f ( x, y ) ∂f ( x, y )
∂x ∂y
-1 1
-1 1 or
1 -1
Which shows changes with respect to x?
Image gradient
∂f ( x, y ) ∂f ( x, y )
∂x ∂y
Effects of noise
Consider a single row or column of the image
• Plotting intensity as a function of position gives a signal
f*g
d
( f ∗ g)
dx
d
• To find edges, look for peaks in ( f ∗ g)
dx Source: S. Seitz
Derivative theorem of convolution
* [1 -1] =
Derivative of Gaussian filter
x-direction y-direction
im = im2double(imread(filemane));
g = fspecial('gaussian',15,2);
imagesc(g);
surfl(g);
gim = conv2(im,g,'same');
imagesc(conv2(im,[-1 1],'same'));
imagesc(conv2(gim,[-1 1],'same'));
dx = conv2(g,[-1 1],'same');
Surfl(dx);
imagesc(conv2(im,dx,'same'));
Finite difference filters
Other approximations of derivative filters exist:
Source: K. Grauman
Practical matters
What is the size of the output?
MATLAB: filter2(g, f, shape) or conv2(g,f,shape)
• shape = ‘full’: output size is sum of sizes of f and g
• shape = ‘same’: output size is same as f
• shape = ‘valid’: output size is difference of sizes of f and g
f f f
g g
g g
g g
Source: S. Lazebnik
Practical matters
What about near the edge?
• the filter window falls off the edge of the image
• need to extrapolate
• methods:
– clip filter (black)
– wrap around
– copy edge
– reflect across edge
Source: S. Marschner
Q?
Practical matters
• methods (MATLAB):
– clip filter (black): imfilter(f, g, 0)
– wrap around: imfilter(f, g, ‘circular’)
– copy edge: imfilter(f, g, ‘replicate’)
– reflect across edge: imfilter(f, g, ‘symmetric’)
Source: S. Marschner
Review: Smoothing vs. derivative filters
Smoothing filters
• Gaussian: remove “high-frequency” components;
“low-pass” filter
• Can the values of a smoothing filter be negative?
• What should the values sum to?
– One: constant regions are not affected by the filter
Derivative filters
• Derivatives of Gaussian
• Can the values of a derivative filter be negative?
• What should the values sum to?
– Zero: no response in constant regions
• High absolute value at points of high contrast
Template matching
Goal: find in image
True detections
False
detections
True detections
Method 2: SSD
h[ m, n] = ∑ ( g[ k , l ] − f [ m + k , n + l ] )2
k ,l
Input 1- sqrt(SSD)
Side by Derek Hoiem
Matching with filters
Goal: find in image
Method 3: Normalized cross-correlation
mean template mean image patch
∑ ( g[k , l ] − g )( f [m + k , n + l ] − f m ,n )
h[ m, n] = k ,l
0.5
2
∑ ( g[ k , l ] − g ) ∑ ( f [ m + k , n + l ] − f m,n )
2
k ,l k ,l
True detections
True detections
A: Depends
Zero-mean filter: fastest but not a great
matcher
SSD: next fastest, sensitive to overall
intensity
Normalized cross-correlation: slowest,
invariant to local average intensity and
contrast
Gaussian
Filter
Source: K. Grauman
Median filter
Salt-and-pepper Median filtered
noise
Gaussian
Median
EXTRA SLIDES
A Gentle Introduction
to Bilateral Filtering
and its Applications
input
* output
*
*
Same Gaussian kernel everywhere.
Bilateral Filter [Aurich 95, Smith 97, Tomasi 98]
No Averaging across Edges
input
* output
*
*
The kernel shape depends on the image content.
Bilateral Filter Definition:
an Additional Edge Term
Same idea: weighted average of pixels.
new
not new new
∑ Gσ (|| p − q ||) Gσ (| I − I q |) I q
1
BF [ I ]p = p
Wp q∈S
s r
pixel
intensity
pixel position
Gaussian Blur and Bilateral Filter
Gaussian blur
p
q GB [ I ]p = ∑ Gσ (|| p − q ||) I q
q∈S
space
space
Bilateral filter
[Aurich 95, Smith 97, Tomasi 98]
p
∑ Gσ (|| p − q ||) Gσ (| I − I q |) I q
1
range
BF [ I ]p = p
q Wp q∈S
s r
space range
normalization
space
q
Space and Range Parameters
∑ Gσ (|| p − q ||) Gσ (| I − I q |) I q
1
BF [ I ]p = p
Wp q∈S
s r
range
p
Exploring the Parameter Space
σr = ∞
σr = 0.1 σr = 0.25 (Gaussian blur)
input
σs = 2
σs = 6
σs = 18
Varying the Range Parameter
σr = ∞
σr = 0.1 σr = 0.25 (Gaussian blur)
input
σs = 2
σs = 6
σs = 18
input
σr = 0.1
σr = 0.25
σr = ∞
(Gaussian blur)
Varying the Space Parameter
σr = ∞
σr = 0.1 σr = 0.25 (Gaussian blur)
input
σs = 2
σs = 6
σs = 18
input
σs = 2
σs = 6
σs = 18