Dip 03 04 05 06
Dip 03 04 05 06
Dip 03 04 05 06
2
2 domains
Spatial Domain : (image plane)
Techniques are based on direct manipulation of pixels in an
image
Frequency Domain :
Techniques are based on modifying the Fourier transform of
an image
There are some enhancement techniques based on
various combinations of methods from these two
categories.
3
Good images
For human visual
The visual evaluation of image quality is a highly subjective
process.
It is hard to standardize the definition of a good image.
For machine perception
The evaluation task is easier.
A good image is one which gives the best machine
recognition results.
A certain amount of trial and error usually is required
before a particular image enhancement approach is
selected.
4
Spatial Domain
5
Mask/Filter
6
Point Processing
Neighborhood = 1x1 pixel
g depends on only the value of f at (x,y)
T = gray level (or intensity or mapping)
transformation function
s = T(r)
Where
r = gray level of f(x,y)
s = gray level of g(x,y)
7
Point Operations
8
Point Processing
Nonlinear Lower
Original Darken Lower Contrast Contrast
Nonlinear Raise
Invert Lighten Raise Contrast Contrast
9
Point Processing
Nonlinear Lower
Original Darken Lower Contrast Contrast
Nonlinear Raise
Invert Lighten Raise Contrast Contrast
10
Contrast Stretching
Produce higher contrast
than the original by
darkening the levels below
m in the original image
Brightening the levels
above m in the original
image
11
Thresholding
Produce a two-level
(binary) image
12
Mask Processing or Filter
Neighborhood is bigger than 1x1 pixel
Use a function of the values of f in a predefined
neighborhood of (x,y) to determine the value of g at
(x,y)
The value of the mask coefficients determine the
nature of the process
Used in techniques
Image Sharpening
Image Smoothing
13
Neighborhood Operations
14
3 basic gray-level transformation
functions
Linear function
Negative
nth root
Negative and identity
transformations
Log
nth power Logarithm function
Log and inverse-log
transformation
Power-law function
Identity Inverse Log
nth power and nth root
transformations
Input gray level, r
15
Identity function
Output intensities are
identical to input
Negative
intensities.
nth root
Is included in the graph
Log
nth power
only for completeness.
L
y=L-x
0 L x
19
Log Transformations
s = c log (1+r)
Negative
c is a constant
nth root
and r 0
Log Log curve maps a narrow
nth power
range of low gray-level
values in the input image
into a wider range of output
levels.
Identity Inverse Log Used to expand the values
of dark pixels in an image
while compressing the
Input gray level, r higher-level values.
20
Log Transformations
It compresses the dynamic range of images with large
variations in pixel values
Example of image with dynamic range: Fourier
spectrum image
It can have intensity range from 0 to 106 or higher.
We can’t see the significant degree of detail as it will
be lost in the display.
21
Example of Logarithm Image
Y=clog10dd
y c log10 (1 x)
x
0 L
c=100
23
Inverse Logarithm Transformations
Do opposite to the Log Transformations
Used to expand the values of high pixels in an image
while compressing the darker-level values.
24
Power-Law Transformations
s = cr
c and are positive
constants
Power-law curves with
fractional values of map a
narrow range of dark input
values into a wider range of
output values
.
c = = 1 Identity function
Input gray level, r
Plots of s = cr for various values
of
(c = 1 in all cases)
25
Gamma correction
26
=1/2.5 = 0.4
Another example : MRI a b
c d
(a) a magnetic resonance image of an
upper thoracic human spine with a
fracture dislocation and spinal cord
impingement
The picture is predominately dark
An expansion of gray levels are desirable
needs < 1
(b) result after power-law
transformation with = 0.6, c=1
(c) transformation with = 0.4
(best result)
(d) transformation with = 0.3
(under acceptable level)
27
Effect of decreasing gamma
When the is reduced too much, the image begins to
reduce contrast to the point where the image started to
have very slight “wash-out” look, especially in the
background
28
Another example a b
c d
(a) image has a washed-out
appearance, it needs a
compression of gray levels
needs > 1
(b) result after power-law
transformation with = 3.0
(suitable)
(c) transformation with = 4.0
(suitable)
(d) transformation with = 5.0
(high contrast, the image has
areas that are too dark, some
detail is lost)
29
Piecewise-Linear Transformation Functions
Advantage:
The form of piecewise functions can be arbitrarily complex
Disadvantage:
Their specification requires considerably more user input
30
Contrast Stretching
x 0 xa
y ( x a ) ya a xb
yb
( x b) y bxL ya
b
x
0 a b L
32
Gray-Scale Modification
33
Gray-level Slicing
Brighten in the
range
Highlighting a specific
range of gray levels in
an image
Display a high value
of all gray levels
in the range of
interest and a low
value for all
other gray levels
(a) transformation
highlights range [A,B]
of gray level and
reduces all others to a
constant level
(b) transformation
highlights range [A,B]
34 but preserves all other
levels
Contrast Stretching
35
Bit-plane slicing
36
Example
37
8 bit planes
Bit-plane 7 Bit-plane 6
38
Bit-plane Slicing
39
Histogram Processing
Histogram of a digital image with gray levels in the
range [0,L-1] is a discrete function
h(rk) = nk
Where
rk : the kth gray level
nk : the number of pixels in the image having gray level rk
h(rk) : histogram of a digital image with gray levels rk
40
Normalized Histogram
dividing each of histogram at gray level rk by the total
number of pixels in the image, n
p(rk) = nk / n
For k = 0,1,…,L-1
p(rk) gives an estimate of the probability of
occurrence of gray level rk
The sum of all components of a normalized
histogram is equal to 1
41
Histogram Processing
Basic for numerous spatial domain processing techniques
Used effectively for image enhancement
Information inherent in histograms also is useful in image
compression and segmentation
42
h(rk) or p(rk)
Example
rk
Dark image
Components of
histogram are
concentrated on the
low side of the gray
scale.
Bright image
Components of
histogram are
concentrated on the
high side of the gray
43
scale.
Example
Low-contrast image
histogram is narrow
and centered toward
the middle of the
gray scale
High-contrast image
histogram covers broad
range of the gray scale
and the distribution of
pixels is not too far from
uniform, with very few
vertical lines being much
44 higher than the others
Histogram Modification
Histogram Stretching
Histogram Shrink
Histogram Sliding
Histogram Stretching
46
Histogram Stretching
47
Histogram Stretching
48
Histogram Shrinking
49
Histogram Shrinking
50
Histogram Sliding
51
Histogram Equalization
As the low-contrast image’s histogram is narrow and
centered toward the middle of the gray scale, if we
distribute the histogram to a wider range the quality
of the image will be improved.
We can do it by adjusting the probability density
function of the original histogram of the image so
that the probability spread equally
52
Histogram transformation
s = T(r)
s Where 0 r 1
T(r) satisfies
(a). T(r) is single-valued
and monotonically
sk= T(rk) increasingly in the
interval 0 r 1
T(r) (b). 0 T(r) 1 for
0r1
0 rk 1 r
53
2 Conditions of T(r)
54
Probability Density Function
The gray levels in an image may be viewed as random
variables in the interval [0,1]
PDF is one of the fundamental descriptors of a random
variable
55
Random Variables
instead of talking about the probability of a specific
value, we talk about the probability that the value of
the random variable lies in a specified range.
In particular, we are interested in the probability that
the random variable is less than or equal to (or,
similarly, greater than or equal to) a specified
constant a.
We write this as
F(a) = P(x a)
56
Random Variables
If this function is given for all values of a (i.e., < a
< ), then the values of random variable x have been
defined.
Function F is called the cumulative probability
distribution function or simply the cumulative
distribution function (cdf).
The shortened term distribution function also is
used.
57
Random Variables
59
Random Variables
Due to the fact that it is a probability,
the cdf has the following properties:
1. F(-) = 0
2. F() = 1
3. 0 F(x) 1
4. F(x1) F(x2) if x1 < x2
5. P(x1 < x x2) = F(x2) – F(x1)
6. F(x+) = F(x),
where x+ = x + , with being a positive,
infinitesimally small number.
60
Random Variables
dF ( x )
p( x )
dx
61
Random Variables
The pdf satisfies the following properties:
62
Random Variables
The preceding concepts are applicable to discrete
random variables.
In this case, there is a finite no. of events and we talk
about probabilities, rather than probability density
functions.
Integrals are replaced by summations and, sometimes,
the random variables are subscripted.
For example, in the case of a discrete variable with N
possible values we would denote the probabilities by
P(xi), i=1, 2,…, N.
63
Random Variables
If a random variable x is transformed by a monotonic
transformation function T(x) to produce a new random
variable y,
the probability density function of y can be obtained
from knowledge of T(x) and the probability density
function of x, as follows:
dx
p y ( y ) px ( x )
dy
where the vertical bars signify the absolute value.
64
Random Variables
65
Applied to Image
Let
pr(r) denote the PDF of random variable r
ps (s) denote the PDF of random variable s
If pr(r) and T(r) are known and T-1(s) satisfies condition (a)
then ps(s) can be obtained using a formula :
dr
p s(s) p r (r)
ds
66
Applied to Image
67
Transformation function
r
s T (r ) ( L 1) pr ( w)dw
0
69
Finding ps(s) from given T(r)
dr
p s ( s ) pr ( r )
ds
r
s T (r ) ( L 1) pr ( w)dw
0
d r
pr ( w)dw ( L 1) pr (r )
ds dT (r )
dr
dr
( L 1)
dr 0
1
ps ( s )
L 1
70
ps(s)
As ps(s) is a probability function, it must be zero outside
the interval [0,1] in this case because its integral over all
values of s must equal 1.
Called ps(s) as a uniform probability density
function
ps(s) is always a uniform, independent of the form of pr(r)
71
Histogram Equalization
72
Discrete
transformation function
74
Example
75
Example
The quality is
not improved
much because
the original
image already
has a broaden
gray-level scale
76
Histogram Equalization
77
Histogram Equalization
78
Histogram Equalization
Histogram
Cumulative
Normalized Histogram
79
Histogram Equalization
transformed intensity
gk = (L-1) * T(k).
To encompass the
whole dynamic range.
80
Example 2
No. of pixels
6
2 3 3 2 5
4 2 4 3 4
3 2 3 5 3
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
81
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
k
n
j 0
j 0 0 6 11 15 16 16 16 16 16
k nj 6 11 15 16 16 16 16 16
s 0 0 / / / / / / / /
j 0 n
16 16 16 16 16 16 16 16
3.3 6.1 8.4
s*9 0 0 9 9 9 9 9
3 6 8
82
Example
No. of pixels
6
3 6 6 3 5
8 3 8 6 4
6 3 6 9 3
2
3 8 3 8
1
Output image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level
83
Histogram equalization
Note
84
Histogram Matching (Specification)
85
Histogram Matching (Specification)
Given a desired histogram, the goal is to transform the image intensity such that the
transformed image has a histogram matches the desired histogram.
Let the initial image histogram be pr, the desired image histogram be pz.
Let T be the function that equalizes the original image and G be the function that
equalizes the desired image.
– r: The initial image intensity.
– s: The image intensity after equalization
– z: The image intensity of the desired image.
– v: The image intensity after equalization of the desired image.
86
Histogram Matching (Specification)
Histogram equalization
r
s T ( r ) ( L 1) pr ( w) dw
0
z
G ( z ) ( L 1) p z (t ) dt s
0 Histogram equalization
Assume G-1 exists and satisfies the condition (a) and (b)
We can map an input gray level r to output gray level z
87
Histogram Matching (Specification)
k k nj
sk T (rk ) ( L 1) pr (rj ) ( L 1) , k 0,1,2,..., L 1
j 0 j 0 n
k
vk G ( z k ) ( L 1) p z ( zi ) sk , k 0,1,2,..., L 1
i 0
88
Procedure Conclusion (continous)
1. Obtain the transformation function T(r) by
calculating the histogram equalization of the input
image
r
s T (r ) ( L 1) pr ( w)dw
0
2. Obtain the transformation function G(z) by
calculating histogram equalization of the desired
density function
z
G ( z ) ( L 1) p z (t )dt s
0
89
Procedure Conclusion
3. Obtain the inversed transformation function G-1
z = G-1(s) = G-1[T(r)]
4. Obtain the output image by applying the processed
gray-level from the inversed transformation function to
all the pixels in the input image
90
Histogram Matching (Specification)
91
Example
92
Example
93
94
95
96
97
Example
Pr(r) 2r 2 ;0 r 1
pr ( r )
2 0 ; elsewhere
1 r
p ( w )dw 1
0
r
98 0 1 2 r
Example
Pz(z)
2z ;0 z 1
2 pz ( z )
0 ; elsewhere
1 z
p ( w )dw 1
z
z 0
99 0 1 2
Step 1:
z
G ( z ) ( 2w )dw
z
z 2
z 2
0
0
101
Step 3:
G( z ) T ( r )
z r 2r
2 2
z 2r r 2
k
sk T ( rk ) pr ( r j )
j 0
k nj
k 0 ,1,2 ,..., L 1
j 0 n
k
G ( z k ) pz ( z i ) sk k 0 ,1,2 ,..., L 1
i 0
z k G 1 T ( rk )
103 G 1
sk k 0 ,1,2 ,..., L 1
Example
Image
104 of Mars moon
Image Equalization
Result image
after histogram
equalization
Transformation function
Histogram of the result image
for histogram equalization
The histogram equalization doesn’t make the result image look better than
the original image. Consider the histogram of the result image, the net
effect of this method is to map a very narrow interval of dark pixels into
the upper end of the gray scale of the output image. As a consequence, the
output
105image is light and has a washed-out appearance.
Solve the problem
Histogram Equalization
106
Histogram Specification
k 0 ,1,2 ,..., L 1
(2) the inverse
transformation G-1(s)
107
Result image and its histogram
108
Note
Histogram specification is a trial-and-error process
There are no rules for specifying histograms, and one
must resort to analysis on a case-by-case basis for any
given enhancement task.
109
Note
Histogram processing methods are global processing, in
the sense that pixels are modified by a transformation
function based on the gray-level content of an entire
image.
Sometimes, we may need to enhance details over small
areas in an image, which is called a local enhancement.
110
a) Original image
(slightly blurred to
reduce noise)
Local Enhancement b) global histogram
equalization (enhance
noise & slightly
increase contrast but
the construction is
not changed)
c) local histogram
equalization using
7x7 neighborhood
(reveals the small
squares inside larger
ones of the original
image.
(a) (b) (c)
define a square or rectangular neighborhood and move the center of this
area from pixel to pixel.
at each location, the histogram of the points in the neighborhood is
computed and either histogram equalization or histogram specification
transformation function is obtained.
another approach used to reduce computation is to utilize nonoverlapping
regions, but it usually produces an undesirable checkerboard effect.
111
Histogram using a local 3*3 neighborhood
112
Explain the result in c)
113
Using Histogram Statistics
L 1
L 1
115
Spatial Filtering
Use of spatial masks for image processing (spatial filters)
116
Spatial Filtering
High-pass filters attenuate or eliminate low-frequency
components (resulting in sharpening edges and other
sharp details).
117
Spatial Filtering
a b
g(x, y) w(s,t) f (x s, y t)
sa tb
118
Spatial Filtering
R w1 z1 w2 z2 ... w9 z9
(for a 3 x 3 filter)
119
Image Enhancement in the
Spatial Domain
120
121
Spatial Correlation and Convolution
Spatial Filtering
Non-linear filters also use pixel neighborhoods but do
not explicitly use coefficients
123
Smoothing Spatial Filters
used for blurring and for noise reduction
blurring is used in preprocessing steps, such as
removal of small details from an image prior to object extraction
bridging of small gaps in lines or curves
noise reduction can be accomplished by blurring with a
linear filter and also by a nonlinear filter
124
Smoothing Linear Filters
output is simply the average of the pixels contained in the
neighborhood of the filter mask.
called averaging filters or lowpass filters.
125
Smoothing Linear Filters
replacing the value of every pixel in an image by the
average of the gray levels in the neighborhood will
reduce the “sharp” transitions in gray levels.
sharp transitions
random noise in the image
edges of objects in the image
thus, smoothing can reduce noises (desirable) and
blur edges (undesirable)
126
3x3 Smoothing Linear Filters
128
General form : smoothing mask
filter of size mxn (m and n odd)
a b
w(s, t ) f ( x s, y t )
g ( x, y ) s at b
a b
w(s, t )
s at b
130
Example
132
Median Filters
replaces the value of a pixel by the median of the gray
levels in the neighborhood of that pixel (the original
value of the pixel is included in the computation of
the median)
quite popular because for certain types of random
noise (impulse noise salt and pepper noise) , they
provide excellent noise-reduction capabilities, with
considering less blurring than linear smoothing filters
of similar size.
133
Median Filters
134
Example : Median Filters
135
Sharpening Spatial Filters
to highlight fine detail in an image
or to enhance detail that has been blurred, either in error
or as a natural effect of a particular method of image
acquisition.
136
Blurring vs. Sharpening
137
Derivative operator
138
First-order derivative
a basic definition of the first-order derivative of a one-
dimensional function f(x) is the difference
f
f ( x 1) f ( x)
x
139
Second-order derivative
similarly, we define the second-order derivative of a one-
dimensional function f(x) is the difference
f
2
f ( x 1) f ( x 1) 2 f ( x)
x 2
140
Foundation
Foundation
First and Second-order derivative of f(x,y)
when we consider an image function of two variables,
f(x,y), at which time we will dealing with partial
derivatives along the two spatial axes.
f ( x, y ) f ( x, y ) f ( x, y )
Gradient operator f
xy x y
Laplacian operator
f ( x , y ) f ( x, y )
2 2
(linear operator) f
2
143 x 2
y 2
Discrete Form of Laplacian
from f 2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
f
2
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
yield,
f [ f ( x 1, y ) f ( x 1, y )
2
f ( x, y 1) f ( x, y 1) 4 f ( x, y )]
144
Result Laplacian mask
145
Laplacian mask implemented an
extension of diagonal neighbors
146
Other implementation of Laplacian
masks
148
Correct the effect of featureless
background
152
Mask of Laplacian + addition
g ( x, y ) f ( x, y ) [ f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1) 4 f ( x, y )]
5 f ( x, y ) [ f ( x 1, y ) f ( x 1, y )
f ( x, y 1) f ( x, y 1)]
0 -1 0
-1 5 -1
0 -1 0
153
Example
154
Note f ( x, y ) f ( x, y )
2
g ( x, y )
f ( x, y ) f ( x, y )
2
0 -1 0 0 0 0 0 -1 0
-1 5 -1 = 0 1 0 + -1 4 -1
0 -1 0 0 0 0 0 -1 0
-1 -1 -1 0 0 0 -1 -1 1
-1 9 -1 = 0 1 0 + -1 8 -1
-1 -1 -1 0 0 0 -1 -1 -1
155
Unsharp Masking and Highboost
filtering
Unsharp Masking and Highboost
Filtering
Unsharp masking
Subtract a blurred version of an image from the image itself
gmask ( x, y) f ( x, y) f ( x, y)
g ( x, y ) f ( x, y ) k * g mask ( x, y ) ,k 1
• A1
• if A = 1, it becomes “standard” Laplacian
sharpening
160
Example
161
f
Gradient Operator Gx x
f f
G y
y
first derivatives are implemented using the
magnitude of the gradient.
1
f mag (f ) [G G ]
2
x
2
y
2
commonly approx.
1
f 2 f 2
2
x y
f Gx Gy
the magnitude becomes nonlinear
162
z1 z2 z3
Gradient Mask
z4 z5 z6
simplest approximation, 2x2 z7 z8 z9
Gx ( z8 z5 ) and Gy ( z6 z5 )
1 1
f [G G ]
2
x
2
y
2
[( z8 z5 ) ( z6 z5 ) ]
2 2 2
f z8 z5 z6 z5
163
z1 z2 z3
Gradient Mask z4 z5 z6
z7 z8 z9
Roberts cross-gradient operators, 2x2
Gx ( z9 z5 ) and Gy ( z8 z6 )
1 1
f [G G ]
2
x
2
y
2
[( z9 z5 ) ( z8 z6 ) ]
2 2 2
f z9 z5 z8 z6
164
Gradient Mask z1 z2 z3
z4 z5 z6
Sobel operators, 3x3 z7 z8 z9
Gx ( z7 2 z8 z9 ) ( z1 2 z 2 z3 )
G y ( z3 2 z6 z9 ) ( z1 2 z 4 z7 )
f Gx Gy
the weight value 2 is to
achieve smoothing by
giving more important
to the
165 center point
Note
the summation of coefficients in all masks equals 0,
indicating that they would give a response of 0 in an area
of constant gray level.
166
Example
167
3.7 Combining Spatial
Enhancement Tools
Example of Combining Spatial
Enhancement Methods
want to sharpen the
original image and bring
out more skeletal detail.
problems: narrow
dynamic range of gray
level and high noise
content makes the
image difficult to
enhance
169
Example of Combining Spatial
Enhancement Methods
solve :
1. Laplacian to highlight fine detail
2. gradient to enhance prominent edges
3. gray-level transformation to increase
the dynamic range of gray levels
170
171
172