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) ),(),( yxfTyxg
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
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))(rTs
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
Ch3. Image enhancement in spatial domain
-7-
Image negatives
–Function:
–Reverse the intensity levels of an image:
positive negativelevelsgray of num where LrLs ,1
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 values0)1log( rcrcs const, where,
Ch3. Image enhancement in spatial domain
-10-
Power-law transformations
–Basic form:const postive and where,
ccrs
Ch3. Image enhancement in spatial domain
-11-
–Gamma correction:
•Intensity-to-voltage
response of CRT:
=1.8~2.5
•If =2.5, s= r
1/2.5
= r
0.4
–Example 3.1 & Fig 3.8
–Example 3.2 & Fig 3.9
Ch3. Image enhancement in spatial domain
Example: Gamma Transformations
Ch3. Image enhancement in spatial domain
Example: Gamma Transformations
Ch3. Image enhancement in spatial domain
Example: Gamma Transformations
Ch3. Image enhancement in spatial domain
-15-
Piecewise-linear
transformation functions
–Contrast stretching:
•Increase the dynamic range
of the gray levels
•If r
1=s
1and r
2=s
2, then
identity function
•If r
1= r
2, s
1=0 and s
2=L-1,
then thresholding function
•In general, r
1r
2and s
1s
2,
so the function is single
valued and monotonically
increasing
Ch3. Image enhancement in spatial domain
-16-
–Gray-level slicing
•Highlighting a specific range of gray level in an image
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
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
Ch3. Image enhancement in spatial domain
Bit-plane Slicing
Ch3. Image enhancement in spatial domain
Bit-plane Slicing
Ch3. Image enhancement in spatial domain
-21-
3.3 Histogram processing
–Histogram function of a digital image:
•Discrete function h(r
k)=n
k, where r
k: k th gray level, n
k:
number of pixels with gray level r
k
–Normalized histogram
•p(r
k)=n
k/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
Ch3. Image enhancement in spatial domain
-22-
Ch3. Image enhancement in spatial domain
-23-
3.3.1 Histogram equalization
–Assume that gray levelris continuous and normalized
to [0,1], that is,
s= T(r)0 r1
–Assume that the transformation function T(r) satisfies
the following conditions:
(a)T(r) is single-valued and monotonically increasing in the
interval 0 r1
(b) 0 T(r)1 for 0 r1
Ch3. Image enhancement in spatial domain
-24-
–If the inverse transformation function
r = T
-1
(s)0 s1 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
sTr
rs
ds
dr
rpsp
r
rdwwprTs
0
)()(
Ch3. Image enhancement in spatial domain
-25-)(
)(
)(
0
rp
dwwp
dr
d
dr
rdT
dr
ds
r
r
r
101
)(
1
)(
)()(
s
rp
rp
ds
dr
rpsp
r
r
rs
If we use CDF for the transformation function, histogram of
the transformed image becomes uniform.
Histogram equalization
Uniform density
-Thus,
[Leibniz’s rule]
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.181,,2,1,0)( Lk
n
n
rp
k
kr 1,,2,1,0
)()(
0
0
Lk
n
n
rprTs
k
j
j
k
j
jrkk
1,,2,1,0)(
1
LksTr
kk
Ch3. Image enhancement in spatial domain
5/11/2024 27
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.
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
in
rprm
rm
rpmrr
: of value mean the is where
ii rrp levelgray of histogram normalized :)( 1
0 0
1
1
0
2
2
)()()(
L
i
ii
rpmrr )(
2
r
measure of average gray level
measure of average contrast
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
Ch3. Image enhancement in spatial domain
-36-
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)),(),(),( yxhyxfyxg
Ch3. Image enhancement in spatial domain
-38-
Ch3. Image enhancement in spatial domain
-39-
3.42 Image averaging
Consider a noisy image g(x,y), original imagef(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),(),(),( yxyxfyxg 2
),(
2
),(
1
1
),()},({
),(
1
),(
yxyxg
K
i
i
K
yxfyxgE
yxg
K
yxg
and
that follows it then ),(),(
1
yxyxg
K
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(
yxfwyxfwyxfw
yxfwyxfwR
Ch3. Image enhancement in spatial domain
-41-
Ch3. Image enhancement in spatial domain
-42-
3.5 Basics of spatial filtering
In general, linear filtering with mx nmask
–w(s,t):convolution mask, or convolution kernel2/)1(,2/)1(
),(),(),(
nbma
tysxftswyxg
a
as
b
bt
where
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
992211
i
ii
zwzwzwzwR
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
Ch3. Image enhancement in spatial domain
45
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
as
b
bt
a
as
b
bt
tsw
tysxftsw
yxg
),(
),(),(
),(
Ch3. Image enhancement in spatial domain
47
Ch3. Image enhancement in spatial domain
48
Example: Gross Representation of Objects
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
Ch3. Image enhancement in spatial domain
50
Example: Use of Median Filtering for Noise
Reduction
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
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( xfxf
x
f
)(2)1()1(
2
2
xfxfxf
x
f
Ch3. Image enhancement in spatial domain
-53-
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 2
nd
-order derivative in x, ydirection)2
2
2
2
2
y
f
x
f
f
),(2)1,()1,(
),(2),1(),1(
2
2
2
2
yxfyxfyxf
y
f
y
yxfyxfyxf
x
f
x
:direction
:direction
Ch3. Image enhancement in spatial domain
-55-
–2-D Laplacian is obtained by summing two components ),(4)1,()1,(),1(),1(
2
yxfyxfyxfyxfyxff
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 tcoefficien center the if
negative is mask Laplacian
the of tcoefficien center the if
),(),(
),(),(
),(
2
2
yxfyxf
yxfyxf
yxg