Spatial Filtering: Image Processing Fourth Year Class ECE Department Semester Two, 2017
Spatial Filtering: Image Processing Fourth Year Class ECE Department Semester Two, 2017
Spatial Filtering
https://sites.google.com/site/elce4011imageprocessing
Subimage pixels
The 3x3 averaging method is one example of the mask operation or Spatial filtering.
The mask operation has the corresponding mask (sometimes called window or template).
w The mask contains coefficients to be multiplied with pixel values.
… Mask frame
… …
p(2,1) p(2,2) p(3,2) w(1,2) w(2,2) w(3,2)
Mask coefficients
Subimage
N M
The reference point y w(i, j ) p (i, j )
of the mask i 1 j 1
Illustration: Computing average value within 3X3 window
Step 1: Move the window to the first location where we want to compute the average value
and then select only pixels inside the window.
x -1 0 1 -1 -2 -1 1 1 1
1
-2 0 2 0 0 0 1 1 1
9
-1 0 1 1 2 1 1 1 1
P P
to compute to compute
x y
3x3 sharpening filter
-1 -1 -1
1
-1 8 -1
9
-1 -1 -1
Order-Statistic Filters
Original image
subimage
Statistic parameters
Mean, Median, Mode,
Min, Max, Etc.
Moving
window
Output image
Median Filter
A median filter is good for removing impulse, isolated noise
Sorted
Moving array
image
window
Salt noise Filter output
Pepper noise
Normally, impulse noise has high magnitude
and is isolated. When we sort pixels in the
moving window, noise pixels are usually
at the ends of the array.
Therefore, it’s rare that the noise pixel will be a median value.
Order-Statistic Filters: Median Filter
A A
13
2D Convolution
2D Convolution is a common image processing technique that changes the intensities of a
pixel to reflect the intensities of the surrounding pixels. A common use of convolution is to
create image filters. Convolution is used to get the popular image effects like blur, sharpen,
and edge detection.
In a similar manner of 1D, the 2D convolution of Kernel w(x,y) and image f(x,y), is given by
the expression:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 00 0 0 0 0
0 0 0 0 00 0 0 0 0
0 0 0 0 00 0 0 0 0
0 0 0
0
0
2D convolution operation Example
2D convolution operation Example
Continue on the operation of moving, multiplying and sum the final result of
Convolution will be as shown
Correlation Similarity to Convolution
No folding (time-reversal)
rxy l x l y l ryx l y l x l
In Matlab:
rxy = Conv(x,fliplr(y))
rxx l x n x n l r l
n
xx l 0, 1, 2,
Convolution, Correlation and Autocorrelation
2D Correlation
Correlation is nearly identical to convolution with only a minor difference,
where instead of multiplying the pixel by the opposite in the kernel, you multiply
it by the equivalent (top-left multiplied by top-left).
2 4 1 2 6
-1 0 1
9 2 3 4 4
-2 0 2
7 2 9 7 6
-1 0 1
5 2 3 6 1