spatial filter
TRANSCRIPT
2
What are images?
• 2D image f(x,y).
•x and y are spatial co-ordinates.
•Amplitude of f at any (x,y) is called intensity or
gray level of the image.
5
OBJECTIVE
The principal objective of enhancement is to process
an images so that the result is more suitable than the
original image for a SPECIFIC application.
Category of image enhancement
• Spatial domain
• Frequency domain
6
WHAT IS???
Spatial filtering (neighborhood processing) is defined by:
A neighborhood
An operation that is performed on the pixels inside
the neighborhood
7
•Typically, the neighborhood is rectangular and its
size is much smaller than that of f(x , y)
e.g., 3x3 or 5x5
Neighborhood
8
Neighborhood
•Coefficients of neighborhood is also called as filter,
mask, filter mask, kernel, template or window.
•Image size is M*N and filter mask size m*n.
•m=2a+1 and n=2b+1.
•a and b are non-negative integers.
9
Assume the
origin of the
mask is the
center of the
mask.
for a 3 x 3 mask,
1 1
1 1
( , ) ( , ) ( , )s t
g x y w s t f x s y t
10
LINEAR V/S NON-LINEAR
A filtering method is linear when the output is
a weighted sum of the input pixels.
Methods that do not satisfy the above property
are called non-linear.
11
Linear Spatial Filtering Methods
Two main linear spatial filtering methods:
Correlation
Convolution
12
Correlation:
•Process of passing the mask w by the image array f.
Convolution
•Often used in applications where we need to
measure the similarity between images or parts of
images
(e.g., pattern matching).
•Similar to correlation except that the mask is first
flipped both horizontally and vertically.
Note: if w(x,y) is symmetric, that is w(x,y)=w(-x,-y),
then convolution is equivalent to correlation!
13
TOOL BOX IMPLEMENTATION
g = imfilter(f, w, filtering_mode, boundary_options,
size_options)
Common syntax
g = imfilter(f, w, ‘replicate’)
14
How do we choose the elements of a
mask?
Typically, by sampling certain functions.
Gaussian1st derivativeof Gaussian
2nd derivativeof Gaussian
Gaussian1st derivativeof Gaussian
2nd derivativeof Gaussian
15
Spatial filters : Smoothing ( low pass)
Use: for blurring and noise reduction.
How it works? The value of every pixel is replaced by the
average of the gray levels in the neighborhood.
Type of smoothing filters:
1. Standard average
2. Weighted average.
3. Median filter
Gaussian
16
1 1 1
1 1 1
1 1 1
9
11 2 1
2 4 2
1 2 1
16
1
Standard average Weighted average13090120110
200989491
100999190
90859682
Standard averaging filter:
(110 +120+90+91+94+98+90+91+99)/9 =883/9 = 98.1
Weighted averaging filter:
(110 +2 x 120+90+2 x 91+4 x 94+2 x 98+90+2 x 91+99)/16 =97.81
17
Mask size determines the degree of smoothing and
loss of detail.
original 3x3 5x5 7x7
15x15 25x25
18
13090120110
200989491
100999590
90859682
95
Steps:
1. Sort the pixels in ascending order:
90,90, 91, 94, 95, 98, 99, 110, 120
2. replace the original pixel value by the median : 95
Median filter(non linear)
19
Very effective for removing “salt and pepper” noise
(i.e., random occurrences of black and white pixels).
Averaging Median filtering
20
Spatial filters : Sharpening ( high pass)
Use: for highlighting fine detail or enhancing
detail that has been blurred.
1st derivativeof Gaussian
1st derivativeof Gaussian
2nd derivativeof Gaussian
Type of sharpening filters:
21
155153156157153
159156158156159
160156154158155
160160158157154
155156157157157
•154*4 – 158- 156-158-158 = -14
•So the value after filter = -14
•We call the resultant image: sharpened image.
•Filtered image=original +sharpened image
•The value in the filter image=154-14 =130
SHARPENING – 1ST DERIVATIVE
•Apply the following laplace on the highlighted pixel
22
155153156157153
159156158156159
160156154158155
160160158157154
155156157157157
•Apply the following laplace 2nd derivative on the highlighted pixel
•154*4 – 158- 156-158-158 = -14
•Apply laplace to all pixels
•Then apply it again to our pixel:-14*4 – 10 -10 – (-6) -4 =-74
•So the value after 2nd derivative filter =-74
•The value of pixel in the filter image=154-74 = 80
SHARPENING – 2nd DERIVATIVE