Mod 3
Mod 3
ENHANCEMENT IN
SPATIAL DOMAIN
By,
Dr.K.Venkateswaran
Professor
Dept. of ECE CMRIT, Bengaluru
Spatial Domain: Some Basic Intensity
Transformation Functions, Histogram Processing,
Fundamentals of Spatial Filtering, Smoothing Spatial
Filters, Sharpening Spatial Filters
Frequency Domain: Preliminary Concepts, The
Discrete Fourier Transform (DFT) of Two Variables,
Properties of the 2-D DFT, Filtering in the Frequency
Domain, Image Smoothing and Image Sharpening
Using Frequency Domain Filters, Selective Filtering.
• It is a Subjective Process.
Point Processing
b) Some neighborhood of (x,y).
This is called ‘Neighborhood processing’.
Neighborhood Processing
f(x,y) g(x,y)
Dept. of ECE, CMRIT,Bengaluru 10
Prob 1: Do the transformation g1(x,y)=f(x,y)+1 and
g2(x,y)=f(x,y)2 . On the image f(x,y).
-2 -1 0
f(x,y) =
0 1 2
4 1 0
g2(x,y)= -2X-2 -1X-1 0X0 =
0X0 1X1 2X2 0 1 4
Dept. of ECE, CMRIT,Bengaluru 11
• The process consists of moving
the origin of the neighborhood
from pixel to pixel and applying
the operator T to the pixels in
the neighborhood to yield the
output at that location.
• The process starts at the top
left of the input image and
proceeds pixel by pixel in a
horizontal scan, one row at
a time.
L-1
s=
r
L-1 r
5 95 150 200
s=r
110 150 190 210
0 10 50 100
5 95 150 200
L-1
s =L-1- r
L-1 r
5 95 150 200
s = 255 - r
110 150 190 210
145 105 65 45
80 45 0 155
L-1
L-1 r
γ
constants.
c= = 1.
33
Contd…
• The locations of (r1,s1) and (r2,s2) control the shape of the
transformation function.
I. If r1= s1 and r2= s2 the transformation is a linear function and
produces no changes.
II. If r1=r2, s1=0 and s2=L-1, the transformation becomes a
thresholding function that creates a binary image
• More on function shapes:
I. Intermediate values of (r1,s1) and (r2,s2) produce various
degrees of spread in the gray levels of the output image,
thus affecting its contrast.
II. Generally, r1≤r2 and s1≤s2 is assumed.
s s
L-1 L-1
r1 = r2
s = s =0
r11 s2 = s21 = L-1
r2
0 L-1 r 0 L-1 r
36
BIT PLANE SLICING
could
• Instead of highlighting gray-level range, we
highlight the contribution made by each bit.
• This method is useful and used in image compression.
• Each pixel in an image represented by 8 bits.
• Image is composed of eight 1-bit planes, ranging from bit-
plane 0 for the least significant bit to bit plane 7 for the most
significant bit.
155 200 50
255 0 50
255 200 255
No. of pixels
Intensity nk with
Value rk intensity
values rk
0 1
50 2
155 1
200 2
255 3
2.5
1.5
0.5
155 200 50
255 0 50
255 200 255
Normalized
values rk nk/MN
0 1 0 1/9
50 2 50 2/9
155 1 155 1/9
200 2 200 2/9
255 3 255 3/9
=1
0.35
0.3
0.25
0.2
0.15
0.1
0.05
1600
1400
1200
1000
800
600
400
200
1600
1400
1200
1000
800
600
400
200
1600
1400
1200
1000
800
600
400
200
1600
1400
1200
1000
800
600
400
200
• Histogram equalization:
– To improve the contrast of an image
– To transform an image in such a way that the
transformed image has a nearly uniform
distribution of pixel values
• In discrete version:
– The probability of occurrence of gray level rk in an image is
p (r ) nk k 0,1,2,..., L 1
r k MN
MN: the total number of pixels in the image
nk : the number of pixels that have gray level rk
L : the total number of possible gray levels in the image
sk
– The transformation function is
T (rk ) (L 1) pr (rj ) (L 1)
nj
k 0,1,2,..., L 1
k k
MN
j 0 j 0
58
Examples of histogram equalization
Dept. of ECE,
CMRIT,Bengaluru 60
Comments:
Histogram equalization may not always produce desirable results,
particularly if the given histogram is very narrow. It can produce false
edges and regions. It can also increase image “graininess” and
• In discrete version:
sk – The probability of occurrence of gray level rk in an image is
k k
T ( r k ) (L 1) pr ( rj ) (L 1)
n
j k 0,1,2,..., L 1
MN
j 0 j 0
rk Histogram sk=T(rk)
Equilization
sk= G(zq)
zq Histogram G(zq)
Equilization
s
k Inverse z1 =G-1 (s )
Transformation of q k
2nd system
1 K
1 K
g f
E g x, y = E i x, y = E i x, y + ηx, y
K K
i=1 i=1
And it that:
2
1 2
σ g x,y = K σ η x,y
2
σ g x,y and σ η2 x,y are the variances of g and η , all at
coordinates (x, y).
• That is; the standard deviation at any point in the average image is
1
σ = σ
g x,y K ηx,y 71
Dept. of ECE, CMRIT,Bengaluru
Filter term in “Digital image processing” is
referred to the subimage
There are others term to call subimage such as
mask, kernel, template, or window
The value in a filter subimage are
referred as coefficients, rather than pixels.
The concept of filtering has its roots in the
use of the Fourier transform for signal processing
in the so-called frequency domain.
Spatial filtering term is the filtering
operations that are performed directly on the
pixels of an image
The process consists simply of moving
the filter mask from point to point in an
image.
At each point (x,y) the response of the
filter at that point is calculated using a
predefined relationship
Basics of Spatial Filtering - Linear
g(x, y) w(s, t) f (x s, y t)
sa t b
a = (m - 1) / 2 b = (n - 1) / 2
a b
g(x, y) w(s, t) f (x s, y t)
sat b
The process of linear filtering similar
to a frequency domain concept called
“convolution”
Simplify expression mn
wz w1 w2 w3
R w1z1 w2 z2 ... wmn zmn 9
i i
w4 w5 w6
i1
w w w
R w1z1 w2 z2 ... w9 z9 wi zi 7 8 9
i1
Where the w’s are mask coefficients, the z’s are the value of the
image gray levels corresponding to those coefficients
Nonlinear spatial filters also operate on
neighborhoods, and the mechanics of sliding
a mask past an image are the same as was
just outlined.
The filtering operation is based
conditionally on the values of the pixels in
the neighborhood under consideration
Smoothing filters are used for blurring
and for noise reduction.
– Blurring is used in preprocessing steps, such as
removal of small details from an image prior to
object extraction, and bridging of small gaps in
lines or curves
– Noise reduction can be accomplished by blurring
There are 2 way of smoothing spatial filters
◦ Smoothing Linear Filters
◦ Order-Statistics Filters(Non Linear)
Linear spatial filter is simply the average of
the pixels contained in the neighborhood of
the filter mask.
Sometimes called “averaging filters”.
The idea is replacing the value of every
pixel in an image by the average of the gray
levels in the neighborhood defined by the
filter mask.
1 1 1 1 2 1
1 1
1 1 1 2 4 2
9 16
1 1 1 1 2 1
1 1 1 1 1
1 1 1 1 1
1
1 1 1 1 1
25
1 1 1 1 1
1 1 1 1 1
The general implementation for filtering
an MxN image with a weighted averaging
filter of size mxn is given by the
expression
a b
w(s, t) f (x s, y t)
sat b
g(x, y) a b
w(s, t)
sat b
Result of Smoothing Linear Filters
Original Image
99
The 1st-order derivative is nonzero along
the entire ramp, while the 2nd-order
derivative is nonzero only at the onset and
end of the ramp.
The response at and around the
point is much stronger for the 2nd-
than for the 1st-order derivative
y2
f(x-1,y) f(x,y) f(x+1,y) 2 f
x2 f (x 1, y) f (x 1, y) 2 f (x, y)
f(x,y-1)
2
f(x,y) f
f (x, y 1) f (x, y 1) 2 f (x, y)
y 2
f(x,y+1)
The digital implementation of the 2-
Dimensional Laplacian is obtained by
summing 2 components
2f 2f
2 f
2 2
x y
2 f f (x 1, y) f (x 1, y) f (x, y 1) f (x, y 1) 4 f (x, y)
1
1 -4 1
1
1 1 1
0 1 0
1 -8 1
1 -4 1
1 1 1
0 1 0
1 0 1
0 -4 0
1 0 1
0 -1 0
-1 4 -1 -1 -1 -1
0 -1 0 -1 8 -1
-1 -1 -1
-1 0 -1
0 4 0
-1 0 -1
The Laplacian filters are
isotropic filters(rotation
invariant).
◦ In the sense that rotating the image and then
applying the filter gives the same result as appling
the filter to the image first and then rotating the
result.
10
Dept. of ECE, CMRIT,Bengaluru 8
f (x, y) 2 f (x, y) When centre co-efficient is negative
g(x, y) When centre co-efficient
f (x, y) 2 f (x, y) is positive
11
0
1. Blur the original image
2. Subtract the blured image from the original (the
resulting difference is called the mask)
3. Add the mask to the original
Letting f ’(x,y) denote the blured image, unsharp masking is
expressed in equation form as follows. First obtain the mask:
gmask(x,y)=f(x,y)-f ’(x,y)
Then we add a weighted portion of the mask back to the
original image:
g(x,y)=f(x,y)+k* gmask(x,y)
When k=1, we have unsharp masking
When k>1, the process is referred to as highboost filtering When
k<1, de-emphasizes the contribution of the unsharp mask
11
1
11
Dept. of ECE, CMRIT,Bengaluru 2
11
3
f(x+1,y)–f(x,y+1)
z4 z5 z6 2 2
f (z9 z5 ) (z8 z6 )
z z z
7 8 9 f z9 z5 z8 z6
These mask are referred to as
the Roberts cross-gradient
operators.
-1 0 0 -1
0 1 1 0
Mask of even size are awkward to apply.
The smallest filter mask should be 3x3.
The difference between the third and
first rows of the 3x3 image region
approximate derivative in x-direction, and
the difference between the third and first
column approximate derivative in y -
direction.
Using this equation
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
11
Dept. of ECE, CMRIT,Bengaluru 9