Chapter2 - Intensity Transformations and Spatial Filtering
Chapter2 - Intensity Transformations and Spatial Filtering
(3.23)
where and are positive constants
17
Power-law curves with fractional values of map a
narrow range of dark input values in to a wider range
of output values, with the opposite being true for
higher values of input levels
The Curves generated with values of have
exactly the opposite effect as those generated with
values of
1 >
1 <
2.2.2 Logarithmic and Contrast-Stretching
Transformations
Logarithmic and contrast-stretching transformations are
basic tools for dynamic range manipulation
g = c log(1 + f)
where c is a constant and f is floating point
The shape of this transformation is similar to the gamma
curve
Note that the shape of gamma curve is variable, whereas the
shape of the log function is fixed
18
2.2.2 Logarithmic and Contrast-Stretching
Transformations
One of the principal uses of the log transformation is to
compress dynamic range
Use MATLAB to do this work for 8 bits
gs = im2uint8(mat2gray(g))
Using mat2gray brings the values to the range [0, 1]
Using im2uint8 brings them to the range [0, 255],
converting the image to class uint8
19
2.2.2 Logarithmic and Contrast-Stretching
Transformations
20
Example of logarithmic transformation
Figure 3.5(a) is a Fourier spectrum with values in the range 0 to 10
6
Figure 3.5(b) shows the result obtained using the commands
2.2.2 Logarithmic and Contrast-Stretching
Transformations
The function of Fig.3.4(a) is called a contrast-stretching
transformation function
It expands a narrow range of input level into a wide range
of output level
Fig.3.4(b) is binary image
This function is called a thresholding function
21
2.2.2 Logarithmic and Contrast-Stretching
Transformations
Fig.3.4(a) has the form
where denotes the intensities of the input image, the
corresponding intensity values in the output image, and
controls the slope of the function
In MATLAB above equation can be represented like
g = 1./(1 + (m./f).^E)
22
2.2.3 Specifying Arbitrary Intensity
Transformations
Suppose that it is necessary to transform the intensities of
an image using a specified transformation function
Let T denote a column vector containing the values of the
transformation function
For example, in the case of an 8-bit image, assume below
mapping
T(1) is the value to which intensity 0 is mapped,
T(2) is the value to which intensity 1 is mapped,
T(256) is the value to which intensity 255 is mapped
23
2.2.3 Specifying Arbitrary Intensity
Transformations
This kind of mapping can be simpley achieved by interp1
function
g = interp1(z, T, f)
where f is the input image, g is the output image, T is the
column vector and z is a column vector of the same length
as T
24
2.3 Histogram Processing
Intensity transformation functions based on information
extracted from image intensity histograms play a
central role in image processing
The focus of this section is on obtaining and using
histograms for image enhancement
25
2.3 Histogram Processing
Example of histogram processing in image enhancement
26
2.3.1 Generating and Plotting Image
Histograms
The histogram of a digital image with L total possible
intensity levels in the range ,0, - is defined as the
discrete function
where
27
( )
k k
h r n =
2.3.1 Generating and Plotting Image
Histograms
Sometimes it is necessary to work with normalized
histograms, obtained simply by dividing all elements of
h(
() and
()
36
}
= =
r
r
dw w p L r T s
0
) ( ) 1 ( ) ( (3.3 4)
) ( ) 1 ( ) ( ) 1 (
) (
0
r p L dw w p
dr
d
L
dr
r dT
dr
ds
r
r
r
=
(
= =
}
(3.3 5)
1 0 ,
1
1
) ( ) 1 (
1
) ( ) ( ) ( s s
= = L s
L r p L
r p
ds
dr
r p s p
r
r r s
(3.3 6)
2.3.2 Histogram Equalization
Additional description of histogram equalization
For the particular values
0
and
0
related with
0
= (
0
), The
probability of the event *
0
+ must equal the probability of
the event *
0
+ because of the one-to-one correspondence
between and
Therefore, PDF of the random variable transformed with
is uniform probability density function
37
}
= =
r
r
dw w p L r T s
0
) ( ) 1 ( ) (
s
( )
s
p s
0
s
1
1
r
( )
r
p r
0
r
2.3.2 Histogram Equalization
Example of implementation of HE
38
2 2 4 4
2 5 5 4
3 5 3 4
3 3 3 3
1 1 6 6
1 7 7 6
4 7 4 6
4 4 4 4
k
s
0/16 0/16 3/16 6/16 4/16 3/16 0/16 0/16
0/16 0/16 3/16 9/16 13/16 16/16 16/16 16/16
0 0 0.18 0.56 0.8 1 1 1
7 0 0 1.3 3.9 5.6 7 7 7
0 0 1 4 6 7 7 7
( )
r k
p r
0
( )
k
r j
j
p r
=
Normalized histogram
CDF
Multiplied by 7
Output gray level
Input image
Output image
Histogram of the input image
Histogram of the output image
1 0 2 3 4 5 7 6
3 3
6
4
1 0 2 3 4 5 7 6
4
6
3 3
2.3.2 Histogram Equalization
Advantage of histogram equalization
Histogram equalization have the tendency of spreading the
histogram of the input image so that the levels of the
histogram-equalized image will span a fuller of the gray
scale
Given an image, the process of histogram equalization
consists simply of implementing Eq.(3.3-8)
which is based on information that can be extracted directly
from the given image, without other parameters
39
1 ,..., 2 , 1 , 0 , ) ( ) (
0 0
= = = =
= =
L k
n
n
r p r T s
k
j
k
j
j
j r k k
2.3.2 Histogram Equalization
The toolbox implements histogram matching using the
following syntax in histeq
g = histeq(f, nlev)
where f is the input image, nlev is the number of
intensity levels specified for the output image
40
2.3.2 Histogram Equalization
Example of histogram equalization
Can you see the difference?
41
2.3.2 Histogram Equalization
The transformation function used in histogram
equalization is the cumulative sum of normalized
histogram values.
Use function cumsum to obtain the transformation
function, as follows
42
2.3.3 Histogram Matching(Specification)
It is useful in some applications to be able to specify the
shape of the histogram that we wish the processed
image to have.
The method used to generate an image that has a
specified histogram is called histogram matching or
histogram specification
43
graylevel
( )
k
H z
0
z
output
gray level
( )
k
H r
0
r
input
2.3.3 Histogram Matching(Specification)
Conceptual diagram of histogram matching
44
0
( ) ( )
input
input
output T input p w dw = =
}
( ) 1
output
p output =
s
( )
s
p s
0
s
1
1
z
( )
z
p z
0
z
one-to-one
one-to-one
r
( )
r
p r
0
r
input
) ( )] ( [
1 1
s G r T G z
= =
}
= =
z
z
s dt t p L z G
0
) ( ) 1 ( ) (
dw w p L r T s
r
r
) ( ) 1 ( ) (
0
}
= =
2.3.3 Histogram Matching(Specification)
In the previous section, the transformation
results in intensity levels, s, with a uniform probability
density function
Suppose now that we define a variable z with the property
Keep in mind that we are after an image with intensity levels,
z, that have the specified density
()
From the preceding two equations, it follows that
45
2.3.3 Histogram Matching(Specification)
Example of implementation of HE
46
(a) Image of the Mars moon Phobos
(b) Histogram equalized image
(c) Result of enhancement by
histogram matching
2.3.4 Function adapthisteq
This toolbox function performs so-called contrast-
limited adaptive histogram equalization (CLAHE)
Neighboring tiles are then combined using bilinear
interpolation to eliminate artificially induced boundaries
The contrast can be limited to avoid amplifying noise
The syntax for adapthisteq is
47
2.3.4 Function adapthisteq
48
2.4 Spatial Filtering
What is the mask?
Some neighborhood operations work with the values of the
image pixels in the neighborhood and the corresponding values
of a subimage that has the same dimensions as the
neighborhood
The subimage is called a filter, mask, kernel, template, or
window
The values in a filter subimage are referred to as coefficients
49
A spatial filter is consisted of
A neighborhood
A predefined operation
Filtering creates a new pixel with coordinates equal to
the coordinates of the center of the neighborhood.
If the operation performed on the image pixels is linear,
than the filter is called a linear spatial filter
Otherwise, the filter is nonlinear spatial filter
2.4 Spatial Filtering
50
2.4.1 Linear Spatial Filtering
Mechanics of Linear filtering
Linear filtering of an image with a
filter mask of size is given
by
where =
1
2
and =
1
2
51
( , ) ( , ) ( , )
a b
s a t b
g x y w s t f x s y t
= =
= + +
2.4.1 Linear Spatial Filtering
Spatial Correlation and Convolution
Correlation is the process of moving a filter mask over the
image and computing the sum of product at each location.
The correlation of a filter mask (, ), of size with a
function (, ), denoted by
The mechanics of convolution are the same, except that the
filter is first rotated by 180
The convolution of (, ), and (, ), denoted by
52
1
( , ) ( , ) ( , ) ( , )
a b
s t b
w x y f x y w s t f x s y t
= =
= + +
1
( , ) ( , ) ( , ) ( , )
a b
s t b
w x y f x y w s t f x s y t
= =
=
(, ) is a blurred version of (, )
80
) , ( ) , ( ) , ( y x f y x f y x g
mask
= (3.6-6)
2.5 Image Processing Toolbox Standard
Spatial Filters
High-boost filtering
A slight further generalization of unsharp masking is called high-boost
filtering
Since (, ) can be obtained using Eq.(3.6-6), Eq.(3.6-7) becomes
81
) , ( * ) , ( ) , ( y x g k y x f y x g
mask
+ =
(3.6-7)
2.5 Image Processing Toolbox Standard
Spatial Filters
Example 3.16
Image enhancement with a high-boost filter
82
By varying the boost coefficient k=4.5,
it generally is possible to obtain an
overall increase in average gray level
of the image, thus helping to brighten
the final result
2.5 Image Processing Toolbox Standard
Spatial Filters
Gradient
The gradient of at coordinates (, ) is defined as the two-
dimensional column vector
The magnitude of this vector is given by
83
x
y
f
G
x
f G
y
c
(
(
(
c
( V = =
(
c
(
(
c
f
2 2 1/ 2 2 2 1/ 2
( ) [ ] [( ) ( ) ]
x y
f f
f mag G G
x y
c c
V = V = + = +
c c
f
x y
f G G V ~ +
(3.6-10)
(3.6-11)
(3.6-12)
2.5 Image Processing Toolbox Standard
Spatial Filters
Roberts cross-gradient operator
and
D
Df
Sobel operator
84
3x3 mask
9 5
( )
x
G z z =
8 6
( )
y
G z z =
2 2 1/ 2
9 5 8 6
[( ) ( ) ] f z z z z V = +
9 5 8 6
| | | | f z z z z V ~ +
7 8 9 1 2 3
3 6 9 1 4 7
| ( 2 ) ( 2 ) |
| ( 2 ) ( 2 ) |
f z z z z z z
z z z z z z
V ~ + + + +
+ + + + +
(3.6-13)
(3.6-14)
(3.6-15)
(3.6-16)
2.5 Image Processing Toolbox Standard
Spatial Filters
Masks of the Robert cross-gradient and Sobel operator
85
Fig. 3.41 (b) and (c) show the masks
of Robert cross-gradient operator
Fig. 3.41 (d) and (e) show the masks
of sobel operator
The coefficients in all the masks
shown in Fig. 3.41 sum to 0
2.5 Image Processing Toolbox Standard
Spatial Filters
Example 3.17
Use of the gradient for edge enhancement
86
Fig. 3.42 (b) shows the gradient obtained using Eq. (3.6-16) with the two sobel
masks in Fig. 3.41(d) and (e)
The edge defects also are quite visible in this image, but with the added
advantage that constant or slowly varying shades of gray have been eliminated
2.5 Image Processing Toolbox Standard
Spatial Filters
Complementary enhancement techniques
Frequently, a given enhancement task will require application
of several complementary enhancement techniques in order to
achieve an acceptable result
Example of combining spatial enhancement methods
Objective
Highlighting fine details
Enhancing prominent edges
Increasing the dynamic range
87
2.5 Image Processing Toolbox Standard
Spatial Filters
Example of combining spatial enhancement
methods(continued)
88
2.5 Image Processing Toolbox Standard
Spatial Filters
Example of combining spatial enhancement
methods(continued)
89
(a) Original (b) Laplacian of original
(c) Sharpened image obtained by
the sum of (a) and (b)
Example of combining spatial enhancement
methods(continued)
2.5 Image Processing Toolbox Standard
Spatial Filters
90
(a) Original (d) Sobel of original
(e) Sobel image smoothed
with a 5x5 averaging filter
Example of combining spatial enhancement
methods(continued)
2.5 Image Processing Toolbox Standard
Spatial Filters
91
(e) Sobel image smoothed
with a 5x5 averaging filter
(f) Mask image formed by the
product of (c) and (e)
(c) Sharpened image obtained by
the sum of (a) and (b)
Example of combining spatial enhancement
methods(continued)
2.5 Image Processing Toolbox Standard
Spatial Filters
92
(a)Original
(g) Sharpened image obtained by
the sum of (a) and (f)
(f) Mask image formed by the
product of (c) and (e)
Example of combining spatial enhancement
methods(continued)
2.5 Image Processing Toolbox Standard
Spatial Filters
93
(g) Sharpened image obtained by
the sum of (a) and (f)
(h) Final result obtained by applying
a power-law transformation to (g) (a)Original
2.6 Using Fuzzy Techniques for Intensity
Transformations and Spatial Filtering
We conclude this chapter with an introduction to fuzzy
sets and their application to intensity transformations and
spatial filtering
Fuzzy sets provide a framework for incorporating human
knowledge in the solution of problems whose
formulation is based on imprecise concepts
94
2.6.1 Background
A set is a collection of objects and set theory consists of
tools that deal with operations on and among sets
Central to set theory is the notion of set membership
We are used to dealing with so-called crisp sets whose
membership can be only true or false in the traditional
sense of bivalued Boolean logic
However, Fuzzy set theory permits the gradual
assessment of the membership of elements in a set
Fuzzy sets provide a formalism for dealing with
imprecise information
95
2.6.2 Introduction to Fuzzy Sets
96
Fig. 3.44 (a) summarizes this concept using an age threshold of 20 years
and letting denote the membership function just discussed
(This kind of membership function is used in crips sets)
Fig. 3.44 (b) shows one possibility. The key feature of this function is the
it is infinite valued, thus allowing a continuous transition between young
and not young
(This kind of membership function is used in Fuzzy sets)
) (z
A
=
=
=
K
v
K
v
v Q
v vQ
v
1
1
0
) (
) (
(3.8-18)
2.6.3 Using Fuzzy Sets
Another example of using Fuzzy set theory
105
2.6.5 Using Fuzzy Sets for Intensity
Transformation
Consider the general problem of contrast enhancement
The process of enhancing the contrast of a gray-scale image using
the following rules
IF a pixel if dark, THEN make it darker
IF a pixel if gray, THEN make it gray
IF a pixel if bright, THEN make it brighter
Keeping in mind that these are fuzzy terms, we can express
the concepts of dark, gray, and bright by the membership
functions in Fig.3.53(a)
106
2.6.5 Using Fuzzy Sets for Intensity
Transformation
In terms of the output, we can consider darker as being
degrees of a dark intensity value, brighter, as being degrees
of a bright shade, and gray as being degrees of an intensity
in the middle of the gray scale
When interpreted as constant intensities whose strength is
modified, the output membership functions are singletons,
as Fig.3.53(b)
107
2.6.5 Using Fuzzy Sets for Intensity
Transformation
The various degree of an intensity in the range [0, 1] occur
when the singletons are clipped by the strength of the
response from their corresponding rules
We are dealing with constants in the output membership
functions, it follows from Eq. (3.8-18) that the output, v0,
to any input, z0, is given by
108
) ( ) ( ) (
* ) ( * ) ( * ) (
0 0 0
0 0 0
0
z z z
v z v z v z
v
bright gray dark
b bright g gray d dark
+ +
+ +
=
(3.8-22)
2.6.5 Using Fuzzy Sets for Intensity
Transformation
Result of a contrast enhancement by using Fuzzy set theory
109
2.6.6 Using Fuzzy Sets for Spatial Filtering
IF - THEN ELSE rules
IF(
1
,
11
) AND (
2
,
12
) AND ... AND (
,
1
) THEN (,
1
)
IF(
1
,
21
) AND (
2
,
22
) AND ... AND (
,
2
) THEN (,
2
)
...
IF(
1
,
1
) AND (
2
,
2
) AND ... AND (
) THEN (,
)
ELSE (,
)
Evaluating the antecedents of the th rule in Eq.(3.8-19) produces
a scalar output,
, given by
= min *
); = 1, 2, , +
ELSE rule is executed when none of the preceding rules is
completely satisfied.
= min *1
; = 1, 2, , +
110
(3.8-19)
2.6.6 Using Fuzzy Sets for Spatial Filtering
in the previous slide is called strength level which
indicates the degree of dominance
If