Chapter2 - Intensity Transformations and Spatial Filtering

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 115

Ch2.

Intensity Transformations and Spatial Filtering


Digital Image Processing using MATLAB, Written by Gonzalez & Woods
Image Processing 2012 Spring
IELAB
1
Introduction
Preview
2.1 Background
2.2 Intensity Transformation Functions
2.3 Histogram Processing and Function Plotting
2.4 Spatial Filtering
2.5 Image Processing Toolbox Standard Spatial Filters
2.6 Using Fuzzy Techniques for Intensity Transformations
and Spatial Filtering

2
Preview
Image enhancement approaches fall into two broad
categories
Spatial domain methods
The term spatial domain refers to the image plane itsef, and approaches in
this category are based on direct manipulation of pixels in an image
Frequency domain methods
This techniques are based on modifying the Fourier transform of an
image
MATLAB formulations representative of processing
techniques in two categories
Neighborhood processing
Spatial convolution
3
Preview
This chapter is focused on spatial filtering methods for
image enhancement
In addition to this, image processing using a fuzzy set
theory will be explained
4
2.1 Background
Spatial domain processes will be denoted by the
expression


where (, ) is the input image, (, ) is the
processed image, and is an operator on , defined over
some neighborhood of (, )
can operate on a set of input images

5
( , ) [ ( , )] g x y T f x y = (3.1 1)
2.1 Background
Definition of a neighborhood
The principal approach in defining a
neighborhood about a point (, ) is
to use a square or rectangular
subimage area centered at (, )
The center of region is moved from
pixel to pixel starting at the top left
corner; it encompasses different
neighborhoods
The operator is applied at each
location (, ) to yield the output,
, at that location
6
( , ) x y
The simplest form of the transformation is when the
neighborhood in Fig.3.1 is of size (a single pixel)

In this case, the value of at (, ) depends only on the
intensity of at that point, and becomes an intensity
or gray-level transformation function

2.2 Intensity Transformation Function
7
2.2 Intensity Transformation Function
Intensity transformation functions are frequently written
in simplified form as
= ()
where and denote the intensity of and ,
respectively

As an example, we will briefly look three basic intensity
transformation functions in the next slide
8
2.2 Intensity Transformation Function
Three basic types of functions
used frequently for image
enhancement
Linear (negative and identity
transformations)
Logarithmic (log and inverse-log
transformations)
Power-law (nth power and nth
root transformations)


9
2.2.1 Functions imadjust and stretchlim
In MATLAB we can do intensity transformations by
using imadjust function which is located in Image
Processing Toolbox

g = imadjust(f, [low_in high_in], [low_out high_out], gamma)

Parameter gamma specifies the shape of the curve that
maps the intensity values in f to create g
10
2.2.1 Functions imadjust and stretchlim






< 1 , the mapping is weighted toward brighter
= 1 , linear mapping
> 1 , the mapping is weighted toward darker

11
2.2.1 Functions imadjust and stretchlim
Example 3.1
Contrast enhancement
using power-law
transformations
(with < 1)
12
As gamma decreased from 0.6 to 0.4, more detail
became visible

A further decrease of gamma to 0.3 enhanced a
little more detail in the background, but began to
reduce contrast to the point where the image
started to have a very slight washed-out look,
especially in the background
Example 3.2
Another illustration of
power-law transformation
(with > 1)
2.2.1 Functions imadjust and stretchlim
13
Suitable results were obtained with gamma
values of 3.0 and 4.0, the letter having a slightly
more appealing appearance because it has higher
contrast

The result obtained with = 5.0 has areas that
are too dark, in which some detail is lost
2.2.1 Functions imadjust and stretchlim
Example of gamma correction
14
When input into the same monitor, this gamma-
corrected input produces an output that is close
in appearance to the original image
2.2.1 Functions imadjust and stretchlim
a. Original digital
mammogram
b. Negative image
c. Result of expanding the
intensity (range [0.5 0.75])
d. Result of expanding the
intensity (gamma = 2)
e. (e) and (f) result of using
function strtchlim as an
automatic input into
function imadjust
15
2.2.1 Functions imadjust and stretchlim
16








cf) Low_High : a two-element vector of a lower and upper limit
Figure MATLAB
(b) g = imcomplement(f)
(c) g2 = imadjust(f, [0.5 0.75], [0 1])
(d) g3 = imadjust(f, [ ], [ ], 2)
Low_High = stretchlim(f)
(e) g = imadjust(f, stretchlim(f), [ ])
(f) g = imadjust(f, stretchlim(f), [1 0])
2.2.1 Functions imadjust and stretchlim
Power-law transformations have the basic form
=

(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

is the kth intensity level in the interval ,0, -


and

is the number of pixels in the image whose


intensity level


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(

) by the total number of pixels in the image, which


we denote by n




where, for integer images, k=0,1,2, ,L-1
28
2.3.1 Generating and Plotting Image
Histograms
The core function in the toolbox for dealing with image
histograms is imhist, with the basic syntax

h = imhist(f, b)

where f is the input image, h is its histogram, and b is the
number of bins used in forming the histogram

We obtain the normalized histogram by using the
expression

p = imhist(f, b)/numel(f)

function numel(f) gives the number of elements in array



29
2.3.1 Generating and Plotting Image
Histograms
Histograms can be plotted also using bar graphs. For this
purpose we can use the function

bar(horz, z, width)

where z is a row vector containing the points to be
plotted, horz is a vector of the same dimension as z that
contains the increments of the horizontal scale, and width
is a number between 0 and 1
30
2.3.1 Generating and Plotting Image
Histograms
Various ways to plot an image histogram


31
A concept of histogram equalization
The method used to generate a processed image that has a
uniform histogram is called histogram equalization
2.3.2 Histogram Equalization
32
gray level
( )
k
H r
input
graylevel
( )
k
H r
output
2.3.2 Histogram Equalization
Suppose that we perform the following transformation
on the input lelvels to obtain output (processed) intensity
levels, s,


where w is a dummy variable of integration
It can be shown that the probability density function of
the output levels is uniform; that is


33
2.3.2 Histogram Equalization
Due to the fact that we are dealing with discrete quantities,
histogram of processed image will not be uniform
For discrete quantities we work with summations, and the
equalization transformation becomes




for k = 0,1,2,L-1, where

is the intensity value in the


output image corresponding to value

in the input image



34
2.3.2 Histogram Equalization
Mathematical derivation of histogram equalization
Let the continuous variable represent the gray levels of the
image
If

() and () are known and


1
() is single-valued and
monotonically increasing, then the probability density function
of the transformed variable can be obtained using the
following equation



where

() and

() is the probability density function of


random variable , , respectively

35
( )
s r
dr
p p r
ds
=
(3.3 3)
2.3.2 Histogram Equalization
Mathematical derivation of histogram equalization
For transformation function () given by the expression


() can be obtained by applying Eq.(3.3-3)






The resulting

always is uniform, independent of the form


of

()


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
= =
=

2.4.1 Linear Spatial Filtering


One-dimensional correlation and convolution

53
2.4.1 Linear Spatial Filtering
Two-dimensional correlation and convolution

54
2.4.1 Linear Spatial Filtering
When interest lies in the characteristic response, , of a
mask either of correlations or convolution, it is convenient
sometimes to write the sum of products as



where the s are the coefficients of an filter and
the s are the corresponding image intensities
encompassed by the filter
55
z w z w z w z w z w R
T
mn
k
k k mn mn
= = + + + =

=1
2 2 1 1
...
(3.4-1)
2.4.1 Linear Spatial Filtering
The Matlab using function imfilter, which has the
following syntax

g = imfilter(f, w, filtering_mode, boundary_options, size_options)

where,
f = input image
w = filter mask
g = filtered result

56
2.4.1 Linear Spatial Filtering
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 (large) object
extraction, and bridging of small gaps in lines or curves
Noise reduction can be accomplished by blurring with a
linear filter and also by nonlinear filtering
57
2.4.1 Linear Spatial Filtering
Averaging filter
The idea behind averaging filters is to replacing the value of
every pixel in an image by the average of the gray levels in
the neighborhood defined by the filter mask
The most obvious application of averaging filter is noise
reduction
Averaging filters have the undesirable side effect that they blur
edges
58
2.4.1 Linear Spatial Filtering
Weighted averaging filter
Pixels are multiplied by different coefficients, thus giving
more importance to some pixels at the expense of others
The general implementation for filtering an image with a
weighted averaging filter of size is given by the
expression
59
( , ) ( , )
( , )
( , )
a b
s a t b
a b
s a t b
w s t f x s y t
g x y
w s t
= =
= =
+ +
=


(3.5 1)
2.4.1 Linear Spatial Filtering
Two 3 3 averaging filter masks
60
2.4.1 Linear Spatial Filtering
Example 3.13
Image smoothing with masks of various sizes
61
2.4.1 Linear Spatial Filtering
The effects of smoothing as a function of filter size
The size of the mask establishes the relative size of the objects
that will be blended with the background

62
Fig. 3.34 shows that a number of
objects have either blended with
the background or their intensity
has diminished considerably
2.4.2 Nonlinear Spatial Filtering
Order-statistic(Nonlinear) filters
Order-statistic filters are nonlinear spatial filters whose
response is based on ordering the pixels contained in the
image area encompassed by the filter, and then replacing the
value of the center pixel with the value determined by the
ranking result
In this section, we are going to focus on median filter which is
one of the most popular order-statistic filters
63
2.4.2 Nonlinear Spatial Filtering
Median filter
Median filter replaces the value of a pixel by the median of
the gray levels in the neighborhood of that pixel
Median filters are particularly effective in the presence of
impulse noise, also called salt-and-pepper noise
The principal function of median filters is to force points with
distinct gray levels to be more like their neighbors
64
2.4.2 Nonlinear Spatial Filtering
Example 3.14
Use of median filtering for noise reduction
65
The image processed with averaging filter has less visible noise, but the price paid is
significant blurring
In general, median filtering is much better suited than averaging for the removal of
salt-and-pepper noise
2.4.2 Nonlinear Spatial Filtering
The toolbox provides two functions for performing
general nonlinear filtering : nlfilter and colfilt
Although colfilt requires more memory, it generally executes
significantly faster than nlfilter

B = colfilt(A, [m n], block_type, fun)

B processes the image A by rearranging each block of A
into a column of a temporary matrix, and then applying the
function fun to this matrix. fun must be a function handle.
colfilt zero-pads A, if necessary
66
2.4.2 Nonlinear Spatial Filtering

B = nlfilter(A, [m n], fun)

B = nlfilter(A, [m n], fun) applies the function fun to each
sliding block of A. fun is a function that accepts an
matrix as input and returns a scalar result.
67
2.4.2 Nonlinear Spatial Filtering
The input image must be padded explicitly before
filtering. For this we use function padarray, which, for 2-
D functions, has the syntax

fp = padarray(f, [r c], method, direction)

where,
f = input image
fp = padded image
[r c] = gives the number of rows and columns by which to pad f
68
2.4.2 Nonlinear Spatial Filtering
method and direction are as explained in Table
69
2.4.2 Nonlinear Spatial Filtering
70
Method
Direction
2.5 Image Processing Toolbox Standard
Spatial Filters
The Matlab supports a number of predefined 2-D linear
spatial filters, obtained by using function fspecial


where,
type specifies the filter type
parameters specifies the filter

71
f = fspecial(type, parameters)
2.5 Image Processing Toolbox Standard
Spatial Filters
The spatial filters that fspecial can generate are
summarized in Table.

72
2.5 Image Processing Toolbox Standard
Spatial Filters
Sharpening
The principal objective of sharpening is to highlight fine detail
in an image or to enhance detail that has been blurred
The sharpening could be accomplished by spatial
differentiation
The strength of the response of a derivative operator is
proportional to the degree of discontinuity of the image at
the point which the operator is applied
Image differentiation enhances edges and other
discontinuities (such as noise) and deemphazises areas with
slowly varying gray-level values
73
2.5 Image Processing Toolbox Standard
Spatial Filters
A basic definition of the first-order derivative of a one-
dimensional function () is difference


A second-order derivative is given by
74
( 1) ( )
f
f x f x
x
c
= +
c
2
2
( 1) ( 1) 2 ( )
f
f x f x f x
x
c
= + +
c
2.5 Image Processing Toolbox Standard
Spatial Filters
Comparing the response between first- and second-order
derivatives
75
First-order derivatives generally
produce thicker edges in an image

Second-order derivatives have a
stronger response to fine detail,
such as thin lines and isolated points

First-order derivatives generally have
a stronger response to a gray-level
step

Second-order derivatives produce a
double response at step change in
gray-level

Second-order derivatives have a
stronger response to a line than to
a step, and to a point than to a line
2.5 Image Processing Toolbox Standard
Spatial Filters
In the most applications, the second derivative is better
suited than the first derivative for image enhancement
because of the ability of the former to enhance fine detail

Although the principle of use of first derivatives in
image processing is for edge extraction, they do have
important uses in image enhancement
76
2.5 Image Processing Toolbox Standard
Spatial Filters
Laplacian
For a function of two variables, Laplacian is defined as


Laplacian is a linear operator
Digital second derivative
Partial second-order derivative in the x-direction


Partial second-order derivative in the y-direction




77
2 2
2
2 2
f f
f
x y
c c
V = +
c c
2
2
( 1, ) ( 1, ) 2 ( , )
f
f x y f x y f x y
x
c
= + +
c
2
2
( , 1) ( , 1) 2 ( , )
f
f x y f x y f x y
y
c
= + +
c
( , ) f x y
(3.6-1)
(3.6-2)
(3.6-3)
2.5 Image Processing Toolbox Standard
Spatial Filters
Digital implementation of the two-dimesional Laplacian
in Eq. (3.6-1)

Laplacian mask


Function fspecial(laplacian, alpha) mask


78
2
[ ( 1, ) ( 1, ) ( , 1) ( , 1)] 4 ( , ) f f x y f x y f x y f x y f x y V = + + + + +
(3.6-4)
0 1 0
1 -4 1
0 1 0
2.5 Image Processing Toolbox Standard
Spatial Filters
Method for image enhancement using the Laplacian


Imaging sharpening with the Laplacian
79
Fig. 3.38(e) shows the result obtained using
Eq. (3.6-5)

The detail in the result image is unmistakably
clearer and sharper than in the original image
| | ) , ( ) , ( ) , (
2
y x f c y x f y x g V + = (3.6-5)
2.5 Image Processing Toolbox Standard
Spatial Filters
Unsharp masking and high-boost filtering
Unsharp masking
Unsharp masking is to subtracting a blurred version of an image from
the image itself
This process is expressed as



where

(, ) denotes the sharpened image obtained by unsharp


masking, and

(, ) 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

2.6.2 Introduction to Fuzzy Sets


Let Z be a set of elements (objects), with a generic element
of Z denoted by z; that is, Z ={z}.
A fuzzy set A in Z is characterized by a membership
function,

(),that associates with each element of Z a


real number in the interval [0,1].
A fuzzy set is an ordered pair consisting of values of z and
corresponding membership function that assigns a grade of
membership to each z. That is,

97
} | ) ( , { Z z z z A
A
e = (3.8-1)
2.6.2 Introduction to Fuzzy Sets
Terminologies and operations of Fuzzy Sets
Empty Set A fuzzy set is empty
Equality Two fuzzy sets A and B are equal
Complement (3.8-2)
Subset (3.8-3)
Union (3.8-4)
Intersection (3.8-5)

98
) ( 1 ) ( z z
A
A
=
) ( ) ( z z
B A
s
)] ( ), ( max[ ) ( z z z
B A U
=
)] ( ), ( min[ ) ( z z z
B A I
=
2.6.2 Introduction to Fuzzy Sets
Example of Fuzzy set operations
99
2.6.3 Using Fuzzy Sets
Example of using Fuzzy set theory
Suppose that we are interested in using color to categorize a given
type of fruit into three groups: verdant, half verdant, and mature.
Verdant fruit is green, half-mature fruit is yellow, and mature fruit
is red.
The problem-specific knowledge just explained can be formalized
in the form of the following fuzzy IF-THEN rules

R1: IF the color is green, THEN the fruit is verdant
OR
R2: IF the color is yellow, THEN the fruit is half-mature
OR
R3: IF the color is red, THEN the fruit is mature
100
2.6.3 Using Fuzzy Sets
101
2.6.3 Using Fuzzy Sets
Figures 3.47 and 3.48, together with the rule base, contain all
the information required to relate inputs and outputs

(3.8-12)

102
3
( , ) m in{ ( ), ( )}
red m at
z v z v =
2.6.3 Using Fuzzy Sets
Let z0 denote a specific value of red, yellow and green. As
noted before, the AND operations is implemented using the
minimum operation:





Three rules are associated by the OR operation. Thus, the
complete fuzzy output is given by




103
)} , ( ), ( min{ ) (
0 3 0 3
v z z v Q
red
=
)} , ( ), ( min{ ) (
0 2 0 2
v z z v Q
yellow
=
)} , ( ), ( min{ ) (
0 1 0 1
v z z v Q
green
=
)}} , ( ), ( max{min{ ) (
0 0
v z z v Q
r s
= (3.8-17)
2.6.3 Using Fuzzy Sets
Q(v) from Eq. (3.8-17) can have
K possible values, Q(1), Q(2),
Q(3), , Q(K), its center of
gravity is given by
104

=
=
=
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

is larger than max(

), we follow the ELSE rule


Otherwise, we follow IF rule
111
2.6.6 Using Fuzzy Sets for Spatial Filtering
We can develop a boundary extraction algorithm based
on a simple fuzzy concept : If a pixel belongs to a
uniform region, then make it white; else make it black,
where, black and white are fuzzy sets
112
2.6.6 Using Fuzzy Sets for Spatial Filtering
In order to do this, a simple set of four IF-THEN rules and
one ELSE rule is used
di = zi z5, where the zs are intensity values
IF
2
is zero AND
6
is zero THEN
5
is white
IF
6
is zero AND
8
is zero THEN
5
is white
IF
8
is zero AND
4
is zero THEN
5
is white
IF
4
is zero AND
2
is zero THEN
5
is white
ELSE
5
is black
113
2.6.6 Using Fuzzy Sets for Spatial Filtering
Membership function of the Fuzzy set and Fuzzy rules
114
2.6.6 Using Fuzzy Sets for Spatial Filtering
Example 3.20
115
The contrast of this image can be improved significantly by expanding the
gray scale.
Fig.3.59(c) was obtained by performing the intensity scaling defined in Eqs.
(2.6-10) and (2.6-11), with k = L 1. the net result is the intensity values in
Fig.3.59(c) span the full gray scale from 0 to (L -1)

You might also like