Taking Derivative by Convolution
Taking Derivative by Convolution
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?
Finite difference filters
Other approximations of derivative filters exist:
Source: K. Grauman
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'));
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
å ( g[k , l ] - g )( f [m + k , n + l ] - f
k ,l
m ,n )
h[ m, n] = 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