Lecture_06 Image Enhancement in Spatial Domain
Lecture_06 Image Enhancement in Spatial Domain
Lecture # 6
Image Enhancement in Spatial Domain- II
ALI JAVED
Lecturer
U.E.T TAXILA
Email:: ali.javed@uettaxila.edu.pk
Linear Filters
Non-Linear Filters
Average Filters
Weighted Average Filters
Median Filters
Minimum Filters
Maximum Filters
Image Histogram
Histogram Equalization
Neighborhood Operations on Images
Neighbourhood operations simply operate on a larger neighbourhood of
pixels than point operations
(x, y)
Neighbourhood
3/31/2011
y Image f (x, y)
Local Operations through Spatial Filtering
The output intensity value at (x,y) depends not only on the
input intensity value at (x,y) but also on the specified
number of neighboring intensity values around (x,y)
3/31/2011
Basics of Spatial Filtering
3/31/2011
Local Operations through Spatial Filtering
x
a b c r s t
d
g
e
h
f
i
* u
x
v
y
w
z
Original Image Filter
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i
3/31/2011
Local Operations through Spatial Filtering
3/31/2011
Types of Spatial Filtering
3/31/2011
Spatial Filtering for Smoothing
For blurring/noise reduction;
Implementation:
The simplest form of the spatial filter for averaging is a square
mask (assume m×m mask) with the same coefficients 1/m2 to
preserve the gray levels (averaging).
3/31/2011
Smoothing Spatial Filters
One of the simplest spatial filtering operations we can
perform is a smoothing operation
1/ 1/ 1/
9 9 9
1/ 1/ 1/
9 9 9
1/ 1/ 1/
9 9 9
99 106 98
95 90 85
*
1/ 100
104
9
1/ 108
9
1/
9
Original Image
Simple 3*3 1/
99 1/ 1/
3*3 Smoothing Pixels
9 98
9 106 9
Neighbourhood 195
/9 190
/9 185
/9
Filter
e = 1/9*106 +
1/ *104 + 1/ *100 + 1/ *108 +
9 9 9
1/ *99 + 1/ *98 +
9 9
y 1/ *95 + 1/ *90 + 1/ *85
Image f (x, y) 9 9 9
= 98.3333
The above is repeated for every pixel in the original image to
generate the smoothed image
3/31/2011
Spatial Filtering for Smoothing:: Example
3/31/2011
Spatial Filtering for Smoothing:: Example
3/31/2011
Weighted Smoothing Spatial Filters
More effective smoothing filters can be generated by allowing
different pixels in the neighbourhood different weights in the
averaging function
1/ 2/ 1/
16 16 16
2/ 4/ 2/
16 16 16
1/ 2/ 1/
16 16 16
3/31/2011
Order Statistics Filtering
Median Filtering
Assigns the mid value of all the gray levels in the mask to the
center of mask;
3/31/2011
Order Statistics Filtering
3/31/2011
Order Statistics Filtering
Minimum Filtering
Assigns the minimum value of all the gray levels in the mask to the center
of mask;
Maximum Filtering
Assigns the maximum value of all the gray levels in the mask to the center
of mask;
Force points with distinct gray levels to be more like their neighbors
3/31/2011
Order Statistics Filtering
3/31/2011
Strange Things Happen At The Edges!
At the edges of an image we are missing pixels to form a
neighbourhood
Origin x
e e
e e e
y Image f (x, y) 3/31/2011
Border Pixels Treatment
Mask operation near the image border
Image Padding
We normally use the gray levels of border pixels to fill up the expanded
region (for 3x3 mask). For larger masks a border region equal to half of the
mask size is mirrored on the expanded region.
3/31/2011
Histogram
The histogram of an image represents the frequency of pixels in an image
Note that the high contrast image has the most evenly spaced histogram
Histograms of low contrast images are located in certain portions and not in
the entire gray scale range
Histogram Equalization
The idea is to find a transformation s=T(r) to be applied to each pixel of the
input image f(x,y) such that a uniform distribution of gray levels in the entire
range results for the output image g(x,y)
Histogram Equalization
Spreading out the frequencies in an image (or equalising the
image) is a simple way to improve dark or washed out images
sk T (rk )
rk: input intensity
sk: processed intensity
k: the intensity (e.g 0.0 – 1.0)
k
pr ( r j )
nj: the frequency of intensity j
n: the sum of all frequencies
j 1
k nj
j 1 n
Histogram Equalization: Example
Histogram Equalization: Example
Notice that the minimum value (52) is now 0 and the maximum value (154) is now 255.
Histogram Equalization: Example
Histogram Equalization: Example
No. of pixels
6
2 3 3 2 5
4 2 4 3 4
3
3 2 3 5
2
2 4 2 4
1
Gray level
4x4 image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9]
histogram
Histogram Equalization: Example
Gray
0 1 2 3 4 5 6 7 8 9
Level(j)
No. of 0 0 6 5 4 1 0 0 0 0
pixels
0 0 6 11 15 16 16 16 16 16
k nj 6 11 15 16 16 16 16 16
s 0 0 / / / / / / / /
j 1 n 16 16 16 16 16 16 16 16
No. of pixels
6
3 6 6 3 5
8 3 8 6 4
3
6 3 6 9
2
3 8 3 8
1
Output image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level
Equalized histogram
Local Enhancement through Histogram Processing
3/31/2011
Local Enhancement through Histogram Processing
3/31/2011
Use of Histogram Statistics for Image Enhancement
Average Intensity
L 1
m ri p(ri )
M 1 N 1
1
MN
f ( x, y )
x 0 y 0
i 0
Variance
M 1 N 1
1
f ( x, y) m
2
MN x 0 y 0
3/31/2011
Use of Histogram Statistics for Image Enhancement
g(x,y) = { E.f(x,y) if mSxy <= k0MG AND k1DG <= <= k2DG }
3/31/2011
Any question