L17 - Mask Processing - 1
L17 - Mask Processing - 1
Spatial Filtering
A pixel value is computed from its old value and the
values of pixels in its vicinity.
We define the neighborhood operations by defining a
neighbourhood of the image pixels
A sub image having the same size as the defined
neighborhood is called a filter, mask, kernel,
template or window.
The values in a filter sub image are referred to as
coefficients and the process is termed as spatial
filtering.
Spatial Filtering Cont..
w(s, t ) f ( x s, y t )
g ( x, y ) s a t b
a b
w( s, t )
s at b
Smoothing Spatial Filters
(Low Pass Filters)
Filtered images
using 3,5,9,15 & 35
pixels.
Example
Example – Noise Reduction
Order Statistics Filter
Spatial filters whose response is based on ordering (ranking)
the pixels contained in the image area encompassed by the
filter.
Replaces the value of the central pixel with the value
determined by the ranking result.
Typical example is a median filter, which replaces the value of
the pixel by the median of the gray levels in the neighbourhood
of the pixel.
Median filters provide excellent noise reduction with less
blurring than linear smoothing filters of the same size
especially in the presence of impulse noise (salt and pepper
noise). This is due to the appearance as black and white dots
superimposed on an image.
Median Filtering
Example
Median Filtering – Noise reduction
Example
Sharpening Spatial Filters
Objective is to highlight fine detail in an image or to enhance
detail that has been blurred, either in error or as a natural
effect of a particular method of image acquisition.
''f i 1 f i 1 2 f i
fi 2
o ( h 2
)
h
Sharpening using first order
derivative operators
The mask operators corresponding to the 1-D discrete
data can be written as [1 -1*], [1* -1] and ½[1 0 -1].
In two dimensions the operators such as Dx = ½[1 0 -1]
and Dy = ½[1 0 -1]T detect edges which lie
perpendicular to the direction of the operator. But we
want an operator which detects edges independent of
their orientation (isotropic edge detector).
So we form the vector operator, the gradient operator.
Sharpening using first order
derivative operators Cont..
The gradient operator is defined as
2 1/ 2
f f
2
f / y
f tan 1
x y f / x
Sharpening using first order
derivative operators Cont..
But due to the computational burden of implementing
the actual equation over the entire image, it is
approximated as
f G x G y
An approximation using absolute z1 z2 z3
value at point z5 using a 3x3 Sobel z4 z5 z6
mask is z7 z8 z9
f z7 2 z8 z9 z1 2 z2 z3 z3 2 z6 z9 z1 2 z4 z7
Prewitt And Sobel Operators
-1 -1 -1 -1 0 1
0 0 0 -1 0 1
1 1 1 -1 0 1
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
Example
Sharpening
Using Sobel
mask
Sharpening using second order
derivative operators
The simplest isotropic derivative operator is the
Laplacian.
For the 2-D image function f(x,y) can be defined as
2
f 2
f
f 2 2
2
x y
The partial second derivative in the x-direction can
be written as
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
Sharpening using second order
derivative operators Cont..
Similarly the partial second derivative in the y-
direction can be written as
2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
2 f 5 f ( x, y ) f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1)
Example
Sharpening using Laplacian
operators
Unsharp Masking & High boost Filtering
Subtracts a blurred version of the image from the
image itself, ie, fs(x,y) = f(x,y) - f’(x,y), where f’(x,y)
is a blurred version of f(x,y) and fs(x,y) is the
sharpened image obtained by unsharp masking.
A generalization of the above method is known as
high boost filtering. A high boost filtered image fhb is
defined by,
Fhb(x,y) = A f(x,y) – f’(x,y) where A ≥ 1
Fhb(x,y) = (A-1) f(x,y) + f(x,y) – f’(x,y)
Fhb(x,y) = (A-1) f(x,y) + fs(x,y)
High boost filtering
Assignment
Read a 256x256 image. Do the following operations.
Filtering using simple averaging masks
Median filtering
Gaussian filtering
Triangular filters (Pyramidal filter, cone filter).
Compare your results.
Read a 256x256 image. Add different types of noise to the image. Do
the noise removal using the following operations.
Simple addition.
Filtering using simple averaging masks
Median filtering
Gaussian filtering
Triangular filters (Pyramidal filter, cone filter).
Compare your results.
Assignment
Read a 256x256 image. Sharpen the image using the following
operators.
Gradient operators.
Laplacian operators.
Histogram specification.
Assignment
log)
Contrast stretching using piecewise linear
transformation.
Gray level slicing.