Image Enhancement - Spatial Domain
Image Enhancement - Spatial Domain
Principle Objective of
What is Image Enhancement? Enhancement
It is a technique of processing an image Process an image so that the result will be
to enhance certain features of the more suitable than the original image for
image a specific application.
The suitableness is up to each application.
Designed to improve the quality of an A method which is quite useful for
image as perceived by a human being enhancing an image may not necessarily be
the best approach for enhancing another
images
3 4
1
Domains Good images
Spatial Domain : (image plane) For human visual
Techniques are based on direct manipulation of The visual evaluation of image quality is a highly
pixels in an image subjective process.
It is hard to standardize the definition of a good
Frequency Domain :
image.
Techniques are based on modifying the Fourier For machine perception
transform of an image
The evaluation task is easier.
There are some enhancement techniques based A good image is one which gives the best machine
on various combinations of methods from these recognition results.
two categories. A certain amount of trial and error usually is
required before a particular image
5 enhancement approach is selected. 6
7 8
2
Types of point operation 1.Brightness modification:
1. Brightness modification it depend on the value associated with
2. Contrast manipulation pixel of the image
3. Histogram manipulation For changing brightness, a constant is
added or subtracted from the luminance
of all sample values
9 10
11 12
3
Contrast Stretching Thresholding
Produce higher Produce a two-level (binary) image
contrast than the
original by
darkening the levels
below m in the original
image
Brightening the levels
above m in the original
image
13 14
15 16
4
3 basic gray-level
transformation functions Identity function
Linear function Output intensities
Negative
nth root
Negative and identity Negative
are identical to input
transformations nth root
intensities.
Log
nth power Logarithm function Log
nth power
Is included in the
Log and inverse-log graph only for
transformation completeness.
Power-law function
Inverse Log
Identity
nth power and nth root Identity Inverse Log
transformations
Input gray level, r
Input gray level, r
17 18
5
Non-Linear Grey Level Transformation
Log Transformations Log Transformations
s = c log (1+r) It compresses the dynamic range of images
c is a constant with large variations in pixel values
and r 0
Log curve maps a narrow Example of image with dynamic range: Fourier
range of low gray-level spectrum image
values in the input image
into a wider range of
It can have intensity range from 0 to 106 or
output levels. higher.
Used to expand the We can‟t see the significant degree of detail
values of dark pixels in as it will be lost in the display.
an image while
compressing the higher-
level values.
21 22
Inverse Logarithm
Example of Logarithm Image Transformations
Do opposite to the Log Transformations
Used to expand the values of high pixels
in an image while compressing the
darker-level values.
6
Non-Linear Grey Level Transformation
Power-Law Transformations Power-Law Transformations
The intensity of light generated by a physical s = cr
device such as CRT is not a linear function of c and are positive
applied signal. constants
Intensity produced at the surface of display is Used in devices where
Gamma correction
Power-law curves with fractional values Cathode ray tube (CRT)
devices have an
of map a narrow range of dark input Monitor
intensity-to-voltage
values into a wider range of output response that is a
power function, with
values, with the opposite being true for varying from 1.8 to 2.5
higher values of input levels. Gamma
correction
= 2.5 The picture will become
darker.
c = = 1 Identity function Gamma correction is
Monitor
done by preprocessing
the image before
inputting it to the
monitor with s = cr1/
27 =1/2.5 = 0.4 28
7
a b
Another example : MRI c d Effect of decreasing gamma
(a) a magnetic resonance image of When the is reduced too much, the
an upper thoracic human spine
with a fracture dislocation and image begins to reduce contrast to the
spinal cord impingement point where the image started to have
The picture is predominately dark
very slight “wash-out” look, especially in
a b
Another example c d Contrast Stretching
(a) image has a washed-out When an image appear very dark because
appearance, it needs a
compression of gray levels of wrong lens aperture setting use
needs > 1 contrast stretching operation
(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) 31 32
8
Contrast Stretching
(a)increase the dynamic range of
the gray levels in the image
(b) a low-contrast image : result
from poor illumination, lack of
dynamic range in the imaging
sensor, or even wrong setting of
a lens aperture of image
acquisition
(c) result of contrast
stretching: (r1,s1) = (rmin,0) and
(r2,s2) = (rmax,L-1)
(d) result of thresholding
33 34
Gray-level slicing
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, Gray-level slicing without
background
(b) transformation highlights
range [A,B] but preserves all
other levels , GS with
Background
35 36
9
Bit plane slicing Bit-plane slicing
Bit plane slicing is a method of Highlighting the
contribution made to total
representing an image with one or more One 8-bit byte Bit-plane 7
(most significant) image appearance by
bits of the byte used for each pixel. specific bits
Main goals Suppose each pixel is
represented by 8 bits
1. convert a gray level image to a binary Higher-order bits contain
image the majority of the visually
Bit-plane 0 significant data
2.Represent an image with fewer bit and (least significant)
Useful for analyzing the
compress the image to a smaller size
relative importance played
by each bit of the image
37 38
8 bit planes
10000000 01000000
0 which results in a binary image, i.e, odd and even pixels are displayed Bit-plane 7 Bit-plane 6
1 which displays all pixels with bit 1 set: 0000.0010
2 which displays all pixels with bit 2 set: 0000.0100
3 which displays all pixels with bit 3 set: 0000.1000 Bit- Bit- Bit-
4 which displays all pixels with bit 4 set: 0001.0000 plane 5 plane 4 plane 3
5 which displays all pixels with bit 5 set: 0010.0000
6 which displays all pixels with bit 6 set: 0100.0000 Bit- Bit- Bit-
7 which displays all pixels with bit 7 set: 1000.0000
plane 2 plane 1 plane 0
39 40
10
% bitplane slicing % 4th bit=0
I=imread('cameraman.tif'); b5=dec2bin(b);
b5(:,5)='0';
subplot(3,2,1);imshow(I);title('original image'); b6=bin2dec(b5);
c3=uint8(b6);
%MSB=0 k2=reshape(c3,256,256);
b=double(I); subplot(3,2,4);imshow(k2);title('4th bit=0');
b1=dec2bin(b); % 2nd bit=0
b1(:,1)='0'; b7=dec2bin(b);
b2=bin2dec(b1); b7(:,7)='0';
c1=uint8(b2); b8=bin2dec(b7);
c4=uint8(b8);
k=reshape(c1,256,256); k3=reshape(c4,256,256);
subplot(3,2,2);imshow(k);title('MSB=0'); subplot(3,2,5);imshow(k3);title('2nd bit=0');
12 16 5 0 16
4 16 8 5 10 Dark image
10 0 4 12 16
5 5
12 0 16 0 8
4
5
3 3 3
4
2
3
A plot of number of occurrences
of grey levels in the image against
2
the grey level values 1
0 4 5 8 10 12 16
Gray Level
44
43
11
Bright image
45 46
Histogram of an image tells a lot about the distribution of grey levels within the
image
47 48
12
h(rk) or p(rk)
13
Histogram transformation Conditions of T(r)
s s = T(r) Single-valued (one-to-one relationship)
Where 0 r 1 guarantees that the inverse transformation will
exist
T(r) satisfies
(a). T(r) is single-
Monotonicity condition preserves the increasing
order from black to white in the output image
valued and
sk= T(rk) monotonically thus it won‟t cause a negative image
T(r)
increasingly in the 0 T(r) 1 for 0 r 1 guarantees that the
interval 0 r 1 output gray levels will be in the same range as
(b). 0 T(r) 1 for the input levels.
0r1
0 rk 1 r
The inverse transformation from s back to r is
53
r = T -1(s) ;0s1 54
14
Random Variables Random Variables
If a random variable x is transformed by a
The pdf satisfies the following properties:
15
Applied to Image Transformation function
Cumulative
Distribution function Finding ps(s) from given T(r)
CDF is an integral of a probability
function (always positive) is the area ds dT ( r )
under the function dr dr
Thus, CDF is always single valued and dr
d ps ( s ) pr ( r )
r
monotonically increasing pr ( w )dw ds
dr 0
Thus, CDF satisfies the condition (a) 1
We can use CDF as a transformation pr ( r ) pr ( r )
pr ( r )
function
1 where 0 s 1
Substitute and yield
63 64
16
r
ps(s) s T ( r ) pr ( w )dw
0
As ps(s) is a probability function, it must
be zero outside the interval [0,1] in this yields
case because its integral over all values
of s must equal 1. Ps(s)
Called ps(s) as a uniform probability
density function a random variable s 1
ps(s) is always a uniform, independent of characterized by
the form of pr(r) a uniform probability
function s
0
65 66
Discrete
transformation function
The probability of occurrence of gray s smin
s ' int eger
* ( L 1) 0.5
level in an image is approximated by 1 smin
pr ( rk )
nk
where k 0 , 1, ..., L-1 Example:
n Suppose we have
The discrete version of transformation r-> 0,1,…….,7 & s-> 0,1,…….,7
k
sk T ( rk ) pr ( r j ) Pr(0)=0, Pr(1)=0.1=Pr(2), Pr(3)=0.3, Pr(4)=0
j 0 Pr(5)=0, Pr(6)=0.4, Pr(7)=0.1
k nj Find out mapping function T(r)
where k 0 , 1, ..., L-1
j 0 n 67 68
17
Histogram Equalization Example
Thus, an output image is obtained by mapping before after Histogram
each pixel with level rk in the input image into a equalization
corresponding pixel with level sk in the output
image
In discrete space, it cannot be proved in
general that this discrete transformation will
produce the discrete equivalent of a uniform
probability density function, which would be a
uniform histogram
69 70
Example Example
No. of pixels
before after Histogram 6
equalization 2 3 3 2 5
4 2 4 3 4
The quality is 3 2 3 5 3
not improved 2
2 4 2 4
much because 1
the original Gray level
image already 4x4 image
0 1 2 3 4 5 6 7 8 9
has a broaden Gray scale = [0,9]
gray-level scale histogram
71 72
18
Example Note
No. of pixels
6 It is clearly seen that
3 6 6 3 5 Histogram equalization distributes the gray level to
reach the maximum gray level (white) because the
8 3 8 6 4 cumulative distribution function equals 1 when
0 r L-1
6 3 6 9 3
If the cumulative numbers of gray levels are slightly
2 different, they will be mapped to little different or
3 8 3 8 same gray levels as we may have to approximate the
1
processed gray level of the output image to integer
Output image number
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level Thus the discrete transformation function can‟t
guarantee the one to one mapping relationship
Histogram equalization
73 74
19
Next, we define a random variable z with the property
Procedure Conclusion
z
G( z ) p ( t )dt s
z Histogram equalization
0
0 1 2 r
79 80
20
Example Discrete formulation
k
We would like to apply the histogram specification with sk T ( rk ) pr ( r j ) (1)
the desired probability density function pz(z) as shown. j 0
k nj
Pz(z) k 0 ,1,2 ,..., L 1 (2)
2z ;0 z 1 j 0 n
2 pz ( z )
0
k
; elsewhere G ( z k ) pz ( z i ) sk k 0 ,1,2 ,..., L 1 (3)
i 0
1 z
p ( w )dw 1
z z k G 1 T ( rk )
(4)
G 1 sk
z 0
0 1 2 k 0 ,1,2 ,..., L 1
81 82
Implementation Implementation
Since we don‟t have the z‟s, we must
resort to some sort of iterative scheme
to find z from s
We are dealing with integers, which
makes this very simple process
Basically vk=sk , so from equation
21
Implementation Implementation
Thus, all we have to do to find the value of zk corresponding to sk
is to iterate on values of z such that this equation is satisfied for
k=0, 1, 2, L-1.
This is the same thing as Eq. (4), except that we do not have to
find the inverse of G because we are going to iterate on z.
Since we are dealing with integers, the closest we can get to
satisfying the equation
(5)
85 86
Implementation Example
The procedure we have just developed for histogram
matching may be summarized as follows:
1. Obtain the histogram of the given image.
2. Use Eq.(1) to pre compute a mapped level sk for each
level rk.
3. Obtain the transformation function G from the given
pz(z) using Eq. (2).
4. Pre compute zk for each value of sk using the iterative
scheme defined in connection with Eq. (5).
5. For each pixel in the original image, if the value of that Image is dominated by large, dark areas,
pixel is rk, map this value to its corresponding level sk; resulting in a histogram characterized by
then map level sk into the final level zk. Use the pre a large concentration of pixels in pixels in
computed values from Steps (2) and (4) for these the dark end of the gray scale
mappings. 87 Image of Mars moon 88
22
Image Equalization Solve the problem Histogram Equalization
Transformation function
Histogram of the result image
for histogram equalization a reasonable approach is to
The histogram equalization doesn’t make the result image look better than modify the histogram of that
the original image. Consider the histogram of the result image, the net image so that it does not have
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 this property
output image is light and has a washed-out appearance. 89 90
23
Note Note
Histogram specification is a trial-and- Histogram processing methods are global
error process processing, in the sense that pixels are
There are no rules for specifying modified by a transformation function
histograms, and one must resort to based on the gray-level content of an
analysis on a case-by-case basis for any entire image.
given enhancement task. Sometimes, we may need to enhance
details over small areas in an image,
which is called a local enhancement.
93 94
a) Original image
(slightly blurred to
reduce noise)
b) global histogram
24
For every pixel, based on the
neighbor hood value the histogram
equalization is done. Here I used 3
by 3 window matrix for explanation.
By changing the window matrix
size, the histogram equalization can
be enhanced. By changing the
values of M and N the window size
can be changed in the code given
below.
Enhancement using
Arithmetic/Logic Operations Logic Operations
Arithmetic/Logic operations perform on Logic operation performs on gray-level
pixel by pixel basis between two or more images, the pixel values are processed as
images binary numbers
except NOT operation which perform light represents a binary 1, and dark
only on a single image represents a binary 0
NOT operation = negative transformation
99 100
25
Example of AND Operation Example of OR Operation
original image AND image result of AND original image OR image result of OR
mask operation mask operation
101 102
103 104
26
Image Subtraction Spatial Filtering
27
Spatial Filtering: Equation Form
a b
Smoothing Spatial Filters
w(s, t ) f ( x s, y t )
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
g ( x, y )
s at b used for blurring and for noise reduction
blurring is used in preprocessing steps,
Filtering can be given such as
in equation form as removal of small details from an image prior
shown above to object extraction
Notations are based bridging of small gaps in lines or curves
on the image shown noise reduction can be accomplished by
to the left blurring with a linear filter and also by a
nonlinear filter
112
113 114
28
3x3 Smoothing Linear Filters Image smoothing
117 118
29
Illustration of Spatial filtering Result of Averaging filter
7 9 11
0 0 0 0 0
10 50 8 7 9 11 8.4 10.7 8.8
0 7 9 11 0
9 5 6 10 50 8 10.3 12.9 5.7
Original Image 0 10 50 8 0
9 5 6 4.1 4.6 3.2
0 9 5 6 0
1 1 1 Original Image Image after Spatial Averaging
1/9 1 1 1 0 0 0 0 0
3x3 5x5
Smoothing Smoothing
filter filter
121 122
30
1 1 1
1
1 1 1
9 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1
1 1 1 1 1
25 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
81 1 1 1 1 1 1 1 1 1
1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
31
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Blur
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
128
a b
c d
General form : smoothing mask Example e f
filter of size mxn (m and n odd) a). original image 500x500 pixel
b). - f). results of smoothing
a b with square averaging filter
w(s, t ) f ( x s, y t ) masks of size n = 3, 5, 9, 15 and
35, respectively.
g ( x, y ) s at b
a b Note:
w(s, t )
s at b
big mask is used to eliminate small
objects from an image.
the size of the mask establishes
the relative size of the objects
that will be blended with the
summation of all coefficient of the mask background.
129 130
32
Order-Statistics Filters
(Nonlinear Filters) Median Filters
the response is based on ordering replaces the value of a pixel by the median of
(ranking) the pixels contained in the the gray levels in the neighborhood of that
image area encompassed by the filter pixel (the original value of the pixel is included
in the computation of the median)
example quite popular because for certain types of
median filter : R = median{zk |k = 1,2,…,n x n} random noise (impulse noise salt and pepper
noise) , they provide excellent noise-reduction
capabilities, with considering less blurring than
note: n x n is the size of the mask
linear smoothing filters of similar size.
131 132
33
Median filter
Example : Median Filters
135
Median filtered Image 136
Image Sharpening
(High-pass filtering) High-pass filtering
to highlight fine detail in an image Image sharpening is achieved in the same
or to enhance detail that has been fashion as image smoothing except that a
blurred, either in error or as a natural different mask image is used called high
effect of a particular method of image pass filter
acquisition.
137 138
34
High-pass filtering High-pass filtering
Consider the 8x8 matrix to perform
image sharpening operation
139 140
values.
141 142
35
First-order derivative Second-order derivative
Derivative of a digital pixel grid can be similarly, we define the second-order
defined in terms of difference derivative of a one-dimensional function
a basic definition of the first-order f(x) is the difference
derivative of a one-dimensional function
2 f
f(x) is the difference f ( x 1) f ( x) [ f ( x 1 1) f ( x 1)]
x 2
f
f ( x 1) f ( x) 2 f
x f ( x 1) f ( x 1) 2 f ( x)
143
x 2 144
Spatial Differentiation
A B
146
36
Using Second Derivatives For Image
The Laplacian
Enhancement
The 2nd derivative is more useful for image The Laplacian is defined as follows:
enhancement than the 1st derivative 2 f 2 f
– Stronger response to fine detail 2 f
– Simpler implementation 2x 2 y
– We will come back to the 1st order derivative
where the partial 1st order derivative in the x
later on direction is defined as follows:
The first sharpening filter we will look at is 2 f
the Laplacian f ( x 1, y ) f ( x 1, y ) 2 f ( x, y)
2 x
– Isotropic and in the y direction as follows:
– One of the simplest sharpening filters 2 f
– We will look at a digital implementation f ( x, y 1) f ( x, y 1) 2 f ( x, y )
2 y
f [ f ( x 1, y ) f ( x 1, y )
2 new image that highlights edges and other
discontinuities
f ( x, y 1) f ( x, y 1)]
4 f ( x, y)
We can easily build a filter based on this
0 1 0
37
But That Is Not Very Enhanced! Laplacian Image Enhancement
The result of a Laplacian filtering
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
38
Discrete Form of Laplacian Result Laplacian mask
from
f 2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y)
x 2
2 f
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 )]
155 156
39
Effect of Laplacian Operator Example
as it is a derivative operator, a). image of the North
pole of the moon
it highlights gray-level discontinuities in an b). Laplacian-filtered
image image with
it deemphasizes regions with slowly varying 1 1 1
gray levels 1 -8 1
grayish edge lines and other discontinuities, c). Laplacian image scaled
for display purposes
all superimposed on a dark,
d). image enhanced by
featureless background. addition with original
image
159 160
0 -1 0
-1 5 -1
0 -1 0
161 162
40
Unsharp masking
Used for edge enhancement
In this approach, a smoothened version
of image is subtracted from the original
image, hence tipping the image balance
towards the sharper content of the
image
163 164
165 166
41
High-boost filtering High-boost filtering
Known as high frequency emphasis filter if the center coefficient
High-boost Masks
A1
if A = 1, it becomes “standard” Laplacian
sharpening 169 170
42
Edges Derivative Filters
172
f
Gx x
f f
Gradient Operator G y
y
Gradient is a 2-D vector that points to first derivatives are implemented using
the direction in which the image intensity the magnitude of the gradient.
grows fastest 1
f mag(f ) [Gx2 G y2 ] 2
1
commonly approx.
f 2 f 2 2
x y
f Gx Gy
173 174
43
z1 z2 z3
z4 z5 z6
Gradient Mask z7 z8 z9
*Gradient magnitude gives the amount of the difference simplest approximation, 2x2
between pixels in the neighborhood which give the strength of
the edge
Gx ( z8 z5 ) and Gy ( z6 z5 )
* Gradient orientation gives the direction of the greatest
change which presumably is the direction across the edge 1 1
f [Gx2 G y2 ] 2
[( z8 z5 ) 2 ( z6 z5 ) 2 ] 2
f z8 z5 z6 z5
175 176
z1 z2 z3 z1 z2 z3
z4 z5 z6 z4 z5 z6
Gradient Mask z7 z8 z9 Gradient Mask z7 z8 z9
f Gx Gy
f z9 z5 z8 z6
the weight value 2 is to
achieve smoothing by
giving more important
177 to the center point 178
44
Note Prewitt operator
179 180
181 182
45
EXAMPLE Using Prewitt operator
183 184
185 186
46
Image Sharpening based on First-Order Derivatives
Using sobel operator
188
187
An image of a
contact lens which
is enhanced in
order to make
defects (at four
and five o’clock in
the image) more
obvious
189
47
Combining Spatial Enhancement Methods Example of Combining Spatial
Successful image Enhancement Methods
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
(a)
Laplacian filter of
bone scan (a)
(b)
Sharpened version of
bone scan achieved (c)
by subtracting (a)
and (b) Sobel filter of bone
scan (a) (d) Image (d) smoothed with
a 5*5 averaging filter
48
Combining Spatial Enhancement Methods
(cont…)
Compare the original and final images
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
196
197
49