1. The document discusses various image filtering techniques, including correlation filtering, convolution, averaging filters, and Gaussian filters.
2. Gaussian filters are commonly used for smoothing images as they remove high-frequency components while maintaining edges. The scale parameter σ controls the amount of smoothing.
3. Median filters can reduce noise in images by selecting the median value in a local neighborhood, unlike mean filters which are susceptible to outliers.
3
How to filter
2dCorrelation
h=filter2(g,f); or h=imfilter(f,g);
2d Convolution
h=conv2(g,f);
],[],[],[
,
lnkmflkgnmh
lk
−−= ∑
f=image
g=filter
],[],[],[
,
lnkmflkgnmh
lk
++= ∑
4.
4
Correlation filtering
Say theaveraging window size is 2k+1 x 2k+1:
Loop over all pixels in neighborhood around
image pixel F[i,j]
Attribute uniform
weight to each pixel
Now generalize to allow different weights depending on
neighboring pixel’s relative position:
Non-uniform weights
5.
5
Correlation filtering
Filtering animage: replace each pixel with a linear
combination of its neighbors.
The filter “kernel” or “mask” H[u,v] is the prescription for the
weights in the linear combination.
This is called cross-correlation, denoted
6.
6
Properties of smoothingfilters
Smoothing
Values positive
Sum to 1 constant regions same as input
Amount of smoothing proportional to mask size
Remove “high-frequency” components; “low-pass” filter
7.
7
Filtering an impulsesignal
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
a b c
d e f
g h i
What is the result of filtering the impulse signal
(image) F with the arbitrary kernel H?
?
8.
8
Filtering an impulsesignal
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
a b c
d e f
g h i
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 i h g 0 0
0 0 f e d 0 0
0 0 c b a 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
What is the result of filtering the impulse signal
(image) F with the arbitrary kernel H?
15
Gaussian filters
What parametersmatter here?
Size of kernel or mask
Note, Gaussian function has infinite support, but discrete
filters use finite kernels
σ = 5 with
10 x 10
kernel
σ = 5 with
30 x 30
kernel
16.
16
Gaussian filters
What parametersmatter here?
Variance of Gaussian: determines extent of
smoothing
σ = 2 with
30 x 30
kernel
σ = 5 with
30 x 30
kernel
18
Smoothing with aGaussian
for sigma=1:3:10
h = fspecial('gaussian‘, fsize, sigma);
out = imfilter(im, h);
imshow(out);
pause;
end
…
Parameter σ is the “scale” / “width” / “spread” of the Gaussian
kernel, and controls the amount of smoothing.
19.
19
Gaussian filters
• Remove“high-frequency” components from the
image (low-pass filter)
Images become more smooth
• Convolution with self is another Gaussian
–So can smooth with small-width kernel, repeat, and
get same result as larger-width kernel would have
–Convolving two times with Gaussian kernel of width σ
is same as convolving once with kernel of width σ√2
• Separable kernel
–Factors into product of two 1D Gaussians
Source: K. Grauman
21
Separability example
*
*
=
=
2D convolution
(centerlocation only)
Source: K. Grauman
The filter factors
into a product of 1D
filters:
Perform convolution
along rows:
Followed by convolution
along the remaining column:
22.
22
Convolution
Convolution:
Flipthe filter in both dimensions (bottom to top, right to left)
Then apply cross-correlation
Notation for
convolution
operator
F
H
24
Key properties oflinear filters
Linearity:
filter(f1 + f2) = filter(f1) + filter(f2)
Shift invariance: same behavior
regardless of pixel location
filter(shift(f)) = shift(filter(f))
Any linear, shift-invariant operator can be
represented as a convolution
Source: S. Lazebnik
25.
25
More properties
• Commutative:a * b = b * a
Conceptually no difference between filter and signal
But particular filtering implementations might break this equality
• 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 Source: S. Lazebnik
31
Practical matters
What happensnear 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
33
Practical matters
What isthe size of the output?
• MATLAB: filter2(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
gg
gg
f
gg
gg
f
gg
gg
full same valid
34.
34
Median filters
A MedianFilter operates over a window by
selecting the median intensity in the window.
What advantage does a median filter have
over a mean filter?
Is a median filter a kind of convolution?
37
Median Filter Example
%%Median
imrgb= imread('peppers.png');
imgray =
im2double(rgb2gray(imrgb));
imnoise = imnoise(imgray,'salt &
pepper',0.1);
imshow(imnoise)
figure
imshow(medfilt2(imnoise))
38.
38
Basic Filters summary
Linearfiltering is sum of dot
product at each position
Can smooth, sharpen, translate
(among many other uses)
Be aware of details for filter size,
extrapolation, cropping
111
111
111