Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
¦w I
i 1
i i
ª17 24 1 15º8
«23 16»»
« 5 7 14 ª8 1 6º
A «4 6 13 22» h ««3 5 7»»
20
« »
«10 12 19 21
3» «¬4 9 2»¼
«¬11 18 25 2 9 »¼
Convolution
• Convolution steps:
– Slide the center element of the kernel to the
pixel to be computed.
– Multiply the convolution weights in the kernel
by the corresponding pixel values in the input
image.
– Sum the individual products from the previous
step. The result is the pixel value for the output
image.
– Repeat over the entire image
Convolution
• Referring to the example, if the kernel is acting on
A(2,4):
ª17 24 1(2) 8(9) 15(4)º
«23 5 7(7) 14(5) 16(3) »»
«
«4 6 13(6) 20(1) 22(8)»
« »
«10 12 19 21 3 »
«¬11 8 25 2 9 »¼
Convolution
• This process is repeated for all of the pixels in the
image, except those at the edges.
• I.e. for a 3x3 convolution kernel, the output image
is two pixels smaller in each dimension owing to
the need for the convolution kernel to act on
neighboring pixels.
Convolution
• This method of “sliding” the kernel across the image
should be reminiscent of the classical definition of 2D
convolution:
gx, y
f x, y ³³ f D, E gx D, y E dDdE
• Where D and E are the dummy variables of
integration, the range of which is across the entire
image.
Convolution
• This is simply an extension of 1D convolution as you
have encountered in signal analysis:
f
f1t
f2 t ³ f t f t W dW
1 2
f
gx, y
f x, y Gu, vFu, v
Linear Filtering and Convolution
• Some practical considerations: application of
kernels in the spatial domain avoids pixels near or
at the edge of the image, since adequate neighbors
do not exist.
• As an alternative, a one-sided kernel can be
applied at the edge, or the edge can be regarded as
a mirror.
Convolution
• Convolution can be accomplished in the frequency
domain, but recall that the transform regards the
image as one period of a periodic function of
infinite extent.
• Regarding the image in this “wraparound” fashion
will usually result in artifacts at the edges.
• The solution commonly used is to place the image
within a larger array in which the borders are
filled with a mean brightness value, or are
smoothly interpolated from the values of the edge
pixels.
Linear Filtering and Convolution
• In many cases, the convolution kernel is separable.
That is, the matrix may be decomposed into a pair
of 1D vectors, that individually applied to rows
and columns, will produce the same result.
• If the separation operation can be performed, the
computation time for filtering can be substantially
reduced.
Filtering
• FIR filters can have linear phase response, which
aids in preventing distortion (just as in the 1D
signal case).
• Infinite impulse response (IIR) filters are difficult
to implement, and tend to be unstable.
• The MATLAB image processing toolbox does not
support IIR filters.
Low-pass Filtering
• Functions such as low-pass filtering would appear
as obvious uses for convolution. There are a
number of additional ones that include:
– Edge sharpening
– Edge detection
– Median filtering
Filtering
• Low pass filtering in medical imaging is most
often used for noise reduction.
• Noise reduction is easily accomplished, but
blurring will result as a byproduct of the filtering
process, and is generally considered undesirable.
• Blurring can be useful however, for elimination of
small details, and joining of gaps in boundaries
prior to segmentation.
Filtering
• The simplest low pass filter implementation is the
averaging filter.
• In this case the output pixel value is simply the
average of the input pixel values taken to some
extent (e.g. 3x3, 5x5, etc.).
• In this case, the elements of the convolution kernel
all have a value of 1.
Averaging Filter
• The effect of the averaging filter is to reduce the
magnitude of sharp transitions.
• These transitions can be either random noise, or
edges – the filter cannot distinguish between the
two.
• In general, blurring is desirable only when
preparing images for segmentation.
Weighted Filtering
• The blurring problem can sometimes be mitigated
using a weighted filter.
• In this case, the weighting factors are determined
as a function of distance from the center (input
pixel) of the convolution kernel.
• Weighting factors decrease with increasing
distance from the center (input pixel).
Filtering
• Compare:
ª1 1 1º
W
1«
1 1 1»
9« » Non-weighted
«¬1 1 1»¼
ª1 2 1º
1« »
W 2 4 2
16 « » Weighted
«¬1 2 1»¼
• The coefficients in front of the kernels preserve
the intensity scaling.
Linear Filtering and Convolution
• The general form of the convolution can be given as
(where the denominator is the sum of the values in
the kernel):
a b
¦ ¦ wk , t f x k , y t
g x, y k a t a
a b
¦ ¦ wk , t
k a t b
m 1
a
2
n 1
b
2