3. Ch3. Image enhancement in spatial domain
-3-
3.1 Background
Two categories in image enhancement
approaches
1) Spatial domain processing
1) Based on direct manipulation of pixels in an image plane
itself
2) Frequency domain processing
• Based on modifying the Fourier transform of an image
Spatial domain processing
–
– Where, f(x,y): input image, g(x,y): processed image, T:
an operator on f, defined over some neighborhood of
(x,y)
)
,
(
)
,
( y
x
f
T
y
x
g
4. Ch3. Image enhancement in spatial domain
-4-
Neighborhood of (x,y)
– Use a square or rectangular subimage area centered at
(x,y):
– Mask (filters, kernels, templates, windows): mask
processing or filtering
5. Ch3. Image enhancement in spatial domain
-5-
– In case of 1x1 (that is, a single pixel): point processing
•
• Where, r: gray level of f(x,y), s: gray level of g(x,y)
• examples:
Contrast stretching: Fig 3.2(a)
Thresholding: Fig 3.2(b)
)
(r
T
s
6. Ch3. Image enhancement in spatial domain
-6-
3.2 Some basic gray level transformations
3 types of gray-
level transformation
functions
1) Linear: negative and
identity
transformations
2) Logarithmic: log and
inverse-log
transformations
3) Power-law: nth
power and nth root
transformations
7. Ch3. Image enhancement in spatial domain
-7-
Image negatives
– Function:
– Reverse the intensity levels of an image:
positive negative
levels
gray
of
num
where
L
r
L
s ,
1
8. Ch3. Image enhancement in spatial domain
-8-
Log transformations
– General form:
– Expand the values of dark pixels while compressing the
higher-level values.
– The opposite is true of the inverse log transformation
– Characteristic: compress the dynamic range of images
with large variations in pixel values
0
)
1
log(
r
c
r
c
s const,
where
,
15. Ch3. Image enhancement in spatial domain
-15-
Piecewise-linear
transformation functions
– Contrast stretching:
• Increase the dynamic range
of the gray levels
• If r1=s1 and r2=s2, then
identity function
• If r1= r2, s1=0 and s2=L-1,
then thresholding function
• In general, r1 r2 and s1s2,
so the function is single
valued and monotonically
increasing
16. Ch3. Image enhancement in spatial domain
-16-
– Gray-level slicing
• Highlighting a specific range of gray level in an image
17. Ch3. Image enhancement in spatial domain
5/11/2024
Highlight the major
blood vessels and study
the shape of the flow of
the contrast medium (to
detect blockages, etc.)
Measuring the actual
flow of the contrast
medium as a function of
time in a series of
images
18. Ch3. Image enhancement in spatial domain
-18-
– Bit-plane slicing:
• Highlighting the specific bit planes
• The higher-order bits contain the majority of the visually
significant data
• Useful for image compression
• Bit-plane 7 is a thresholded (binary) image with 127
• Fig 3.13 & 3.14
21. Ch3. Image enhancement in spatial domain
-21-
3.3 Histogram processing
– Histogram function of a digital image:
• Discrete function h(rk)=nk, where rk : k th gray level, nk :
number of pixels with gray level rk
– Normalized histogram
• p(rk)=nk/n, for k=0,1,…,L-1, where n : total number of
pixels
• Sum of all components of the normalized histogram is
equal to 1
– Fig 3.15
• High dynamic range uniform distribution
histogram equalization
23. Ch3. Image enhancement in spatial domain
-23-
3.3.1 Histogram equalization
– Assume that gray level r is continuous and normalized
to [0,1], that is,
s = T(r) 0 r 1
– Assume that the transformation function T(r) satisfies
the following conditions:
(a)T(r) is single-valued and monotonically increasing in the
interval 0 r 1
(b) 0 T(r) 1 for 0 r 1
24. Ch3. Image enhancement in spatial domain
-24-
– If the inverse transformation function
r = T-1(s) 0 s 1 satisfies the above conditions,
then
– If we use CDF(Cumulative Distribution Function) of r for
the transformation function, that is,
– Then, the above equation satisfies both conditions of (a)
and (b).
PDF
is
p()
where
,
)
(
)
(
)
(
1
s
T
r
r
s
ds
dr
r
p
s
p
r
r dw
w
p
r
T
s
0
)
(
)
(
25. Ch3. Image enhancement in spatial domain
-25-
)
(
)
(
)
(
0
r
p
dw
w
p
dr
d
dr
r
dT
dr
ds
r
r
r
1
0
1
)
(
1
)
(
)
(
)
(
s
r
p
r
p
ds
dr
r
p
s
p
r
r
r
s
If we use CDF for the transformation function, histogram of
the transformed image becomes uniform.
Histogram equalization
Uniform density
- Thus,
[Leibniz’s rule]
26. Ch3. Image enhancement in spatial domain
-26-
– In digital image, gray level is discrete. Thus,
and, transformation function for histogram equalization
is
– also, inverse transformation function is
– Example 3.3, Fig 3.17, and Fig 3.18
1
,
,
2
,
1
,
0
)
(
L
k
n
n
r
p k
k
r
1
,
,
2
,
1
,
0
)
(
)
(
0
0
L
k
n
n
r
p
r
T
s
k
j
j
k
j
j
r
k
k
1
,
,
2
,
1
,
0
)
(
1
L
k
s
T
r k
k
28. Ch3. Image enhancement in spatial domain
-31-
3.3.3 Local enhancement
Histogram processing for entire image: global
Local histogram processing:
– Define a square or rectangular neighborhood and move the
center of this area from pixel to pixel. At each location,
histogram equalization or histogram matching is obtained
– Another approach is to utilize non-overlapping regions, but it
usually produces an undesirable checkerboard effect.
29. Ch3. Image enhancement in spatial domain
-32-
3.3.4 Use of histogram statistics for
image enhancement
Some statistical parameters obtainable directly from
the histogram for image enhancement
nth moment:
– and . The second moment is
variance of r ( )
)
(
)
(
)
(
)
(
1
0
1
0
i
L
i
i
L
i
i
n
i
n
r
p
r
m
r
m
r
p
m
r
r
:
of
value
mean
the
is
where
i
i r
r
p level
gray
of
histogram
normalized
:
)
(
1
0
0
1
1
0
2
2 )
(
)
(
)
(
L
i
i
i r
p
m
r
r
)
(
2
r
measure of average gray level
measure of average contrast
30. Ch3. Image enhancement in spatial domain
-35-
3.4 Enhancement using
arithmetic/logic operations
Arithmetic/logic operations: pixel-by-pixel basis
Arithmetic operations
– Image subtraction
– Image addition
– Image multiplication
– Image division
Logic operations
– NOT: negative transformation
– AND/OR
• Used for masking
• Masking is ROI(region of interest) processing
32. Ch3. Image enhancement in spatial domain
-37-
3.4.1 Image subtraction
Difference between f(x,y) and h(x,y):
Subtraction is the enhancement of difference between
images.
Fig 3.28:
Example 3.7, Fig 3.29
Comments on implementation
– The difference image can range –255~255 => need to scale to
0~255
• Add 255 and then divide by 2
• (diff image – min)x255/max; max: maximum of (diff image – min)
image
Image subtraction can be used for segmentation (changes)
)
,
(
)
,
(
)
,
( y
x
h
y
x
f
y
x
g
34. Ch3. Image enhancement in spatial domain
-39-
3.42 Image averaging
Consider a noisy image g(x,y), original image f(x,y), noise
(x,y)
At every (x,y), assume that noise is uncorrelated and has
zero average, then averaging K different noisy images
Example 3.8, Fig 3.30, 3.31
)
,
(
)
,
(
)
,
( y
x
y
x
f
y
x
g
2
)
,
(
2
)
,
(
1
1
)
,
(
)}
,
(
{
)
,
(
1
)
,
(
y
x
y
x
g
K
i
i
K
y
x
f
y
x
g
E
y
x
g
K
y
x
g
and
that
follows
it
then
)
,
(
)
,
(
1
y
x
y
x
g
K
35. Ch3. Image enhancement in spatial domain
-40-
3.5 Basics of spatial filtering
Response of linear filtering with 3x3 mask at (x,y)
– Fig 3.32
)
1
,
1
(
)
1
,
1
(
)
,
1
(
)
0
,
1
(
)
,
(
)
0
,
0
(
)
,
1
(
)
0
,
1
(
)
1
,
1
(
)
1
,
1
(
y
x
f
w
y
x
f
w
y
x
f
w
y
x
f
w
y
x
f
w
R
37. Ch3. Image enhancement in spatial domain
-42-
3.5 Basics of spatial filtering
In general, linear filtering with m x n mask
– w(s,t): convolution mask, or convolution kernel
2
/
)
1
(
,
2
/
)
1
(
)
,
(
)
,
(
)
,
(
n
b
m
a
t
y
s
x
f
t
s
w
y
x
g
a
a
s
b
b
t
where
38. Ch3. Image enhancement in spatial domain
-43-
Fig 3.33: 3x3 spatial filter mask
Nonlinear spatial filters
– Filtering operation is based conditionally on the values
of the pixels in the neighborhood under consideration
– Example: median filtering
Handling methods for boarder pixels
1) Not process the pixels at a distance no less than (n-
1)/2 pixels from the border
2) “padding” the image by adding rows and columns of
0’s
9
1
9
9
2
2
1
1
i
i
i z
w
z
w
z
w
z
w
R
39. Ch3. Image enhancement in spatial domain
-44-
3.6 Smoothing spatial filters
Smoothing linear filters
– Used for blurring and for noise reduction
– Averaging filter, or lowpass filter
– Undesirable side effect: blur edges
– Fig 3.34: (a)box filter, (b)weighted average
41. Ch3. Image enhancement in spatial domain
-46-
3.6 Smoothing spatial filters
Smoothing linear filters
– General implementation for weighted average filtering
– Example 3.9 & Fig 3.35, Fig 3.36
a
a
s
b
b
t
a
a
s
b
b
t
t
s
w
t
y
s
x
f
t
s
w
y
x
g
)
,
(
)
,
(
)
,
(
)
,
(
44. Ch3. Image enhancement in spatial domain
-49-
3.6.2 Order-statistics filters
Based on ordering (ranking) the pixels: nonlinear
spatial filters
Median filter
– Replace the value of a pixel by the median of the gray
levels in the neighborhood of that pixel
– advantages:
• Excellent noise reduction capabilities
• Less blurring than linear smoothing filters of similar size
• Effective in the presence of impulse noise (or salt-and
pepper noise)
– Example 3.10
45. Ch3. Image enhancement in spatial domain
50
Example: Use of Median Filtering for Noise
Reduction
46. Ch3. Image enhancement in spatial domain
-51-
3.7 Sharpening spatial filters
Sharpening:
– To highlight fine detail in an image
– To enhance detail that has been blurred
Applications
– Electronic printing
– Medical imaging
– Industrial inspection
– Autonomous guidance in military systems
Accomplished by spatial differentiation
47. Ch3. Image enhancement in spatial domain
-52-
3.7.1 Foundation
First-order derivative of 1-D function f(x)
second-order derivative of 1-D function f(x)
Fig 3.38
– First-order derivatives
• Produce thicker edges
• Stronger response to a gray-level steps
– Second-order derivatives
• Stronger response to fine detail, such as thin lines and isolated
points
• Double response at step changes in gray-level
)
(
)
1
( x
f
x
f
x
f
)
(
2
)
1
(
)
1
(
2
2
x
f
x
f
x
f
x
f
49. Ch3. Image enhancement in spatial domain
-54-
3.7.2 Laplacian
– Isotropic filter: independent of the direction rotation
invariant
Development of the method
– Lapacian: simplest isotropic derivative operator, Linear
operator
– discrete form (partial 2nd-order derivative in x, y direction)
2
2
2
2
2
y
f
x
f
f
)
,
(
2
)
1
,
(
)
1
,
(
)
,
(
2
)
,
1
(
)
,
1
(
2
2
2
2
y
x
f
y
x
f
y
x
f
y
f
y
y
x
f
y
x
f
y
x
f
x
f
x
:
direction
:
direction
50. Ch3. Image enhancement in spatial domain
-55-
– 2-D Laplacian is obtained by summing two components
)
,
(
4
)
1
,
(
)
1
,
(
)
,
1
(
)
,
1
(
2
y
x
f
y
x
f
y
x
f
y
x
f
y
x
f
f
51. Ch3. Image enhancement in spatial domain
-56-
– Adding the original and Laplacian images (superimpose)
– Example 3.11 & Fig 3.40
positive
is
mask
Laplacian
the
of
t
coefficien
center
the
if
negative
is
mask
Laplacian
the
of
t
coefficien
center
the
if
)
,
(
)
,
(
)
,
(
)
,
(
)
,
( 2
2
y
x
f
y
x
f
y
x
f
y
x
f
y
x
g