Mpa 3
Mpa 3
Image Enhancement-
What Is Image Enhancement?
Image enhancement is the process that
improves the quality of the image for a
specific application
The reasons for doing this include:
◦ Highlighting interesting detail in images
◦ Removing noise from images
◦ Making images more visually appealing
Spatial & Frequency Domains
There are two broad categories of image
enhancement techniques
◦ Spatial domain techniques
Direct manipulation of image pixels
◦ Frequency domain techniques
Manipulation of Fourier transform or wavelet
transform of an image
Spatial Domain Enhancement
The term spatial domain refers to the aggregate of
pixels composing an image. Spatial domain methods
are procedures that operate directly on these pixels.
0 r 255
The user may input both values of ‘m’ and ‘c’
Brightness
255
Consider the picture of Einstein here.
0 r 255
c = -80 c = 80
0.02
0.018
0.016
0.014
0.012
0.01
0.008
0.006
0.004
0.002
0
0 50 100 150 200 250
0.18
0.16
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
0.02
0.018
0.016
0.014
0.012
0.01
0.008
0.006
0.004
0.002
0
0 50 100 150 200 250
Contrast
255
Consider again the picture of Einstein.
0 r 255
m = 3.0 m = 0.3
0.02
0.018
0.016
0.014
0.012
0.01
0.008
0.006
0.004
0.002
0
0 50 100 150 200 250
0.2
0.15
0.1
0.05
0
0 50 100 150 200 250
0.07
0.06
0.05
0.04
0.03
0.02
0.01
0
0 50 100 150 200 250
Basic Point Processing
Identity Functions
◦ Output intensities are identical to input
intensities
◦ This function doesn’t have an effect on an
image, it was included in the graph only for
completeness
◦ Its expression:
s=r
Negative Functions
◦ The negative of an image
with gray level in the range
[0, L-1], where L = Largest
value in an image, is
obtained by using the
negative transformation’s
expression:
s=L–1–r
s = c log(1+r)
c: constant, r≥0
Log
Inverse Logarithmic Transformations
◦ Do opposite to the
log transformations
◦ Used to expand the
values of high pixels
in an image while
compressing the
darker-level values.
Power-Law Transformation
s cr
c, : positive constants
r1 = r2= 102
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
0.5
0.45
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
0 50 100 150 200 250
Intermediate values of (r1,s1) and (r2,s2) produce various degrees of spread in the
gray levels of the output image, thus affecting its contrast.
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
Summary of Contrast Stretching
The locations of points (r1, s1) and (r2, s2)
control the shape of the transformation
function.
If r1 = s1 and r2 = s2, the transformation is
a linear function that produces no changes
in gray levels.
If r1 = r2, s1 = 0 and s2 = L-1, the
transformation becomes a thresholding
function that creates a binary image.
Intermediate values of (r1, s1) and (r2, s2)
produce various degrees of spread in the
gray levels of the output image, thus
affecting its contrast.
The result of contrast stretching, obtained
by setting (r1, s1) = (rmin, 0) and (r2, s2) =
(rmax,L-1) where rmin and rmax denote the
minimum and maximum gray levels in the
image, respectively. Thus, the transformation
function stretched the levels linearly from
their original range to the full range [0, L-1].
In general, r1 ≤ r2 and s1 ≤ s2 is assumed,
so the function is always increasing.
Problem on Contrast Stretching
Gray 0 1 2 3 4 5 6 7
levels
No of 0 0 5 20 20 19 0 0
occure
nces
In the case of a dark image, the components of the histogram are concentrated on
the low side of the gray scale.
Similarly the components of the histogram of a bright image are concentrated on the
high side of the gray scale.
0.18
0.16
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
0.02
0.018
0.016
0.014
0.012
0.01
0.008
0.006
0.004
0.002
0
0 50 100 150 200 250
In the case of a low contrast image the histogram is narrow and centered towards the
middle of the gray scale.
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
How to calculate Histogram in programming
// f(0…M-1, 0…N-1)=image // f(0…M-1, 0…N-1)=image
// h(0…255)=histogram =0; // h(0…255)=histogram =0;
for k=0 to 255
{ for i=0 to M-1
for i=0 to M-1 {
{ for j=0 to N-1
for j=0 to N-1 {
{ a=f(i,j);
if f[i,j]==k h[a]+=1;
{ }
h[k]+=1; }
}
}
}
} // Loop=MXN
//Loop=MXNX256
Why Histogram?
Histograms are the basis for numerous
spatial domain processing techniques
Histogram manipulation can be used
effectively for image enhancement
Histograms can be used to provide useful
image statistics
Information derived from histograms are
quite useful in other image processing
applications, such as image compression
and segmentation.
Why Histogram?
4
x 10
4
3.5
2.5
1.5
0.5
44
Another Example
7000
6000
5000
4000
3000
2000
1000
Over-exposed image
An image whose pixels tend to occupy
the entire range of possible gray levels, in
addition, tend to be distributed uniformly,
will have an appearance of high contrast
and will exhibit a large variety of gray
tones.
Histogram Equalization
What is the histogram equalization?
The histogram equalization is an approach to enhance a given
image. The approach is to design a transformation T(.) such that
the gray values in the output is approximately uniformly
distributed in [0, 1].
Let us assume for the moment that the input image to be
enhanced has gray values, with r = 0 representing
black and r = 1 representing white.
49
Histogram Equalization
s T (r ) 0 r L 1
a. T(r) is a strictly monotonically increasing function
in the interval 0 r L -1;
b. 0 T (r ) L -1 for 0 r L -1.
8/21/2024 50
How to implement histogram equalization?
nk
pr (rk ) 0 rk 1 0 k L 1
n
L: Total number of gray levels
nk: Number of pixels with gray value rk
k
sk T (rk ) pr (rj ) 0 k L 1
j 0
Effect of applying the Histogram Equalization.
0.02
0.018
0.016
0.014
0.012
0.01
0.008
0.006
0.004
0.002
0
0 50 100 150 200 250
0.02
0.018
0.016
0.014
0.012
0.01
0.008
0.006
0.004
0.002
0
0 50 100 150 200 250
Another example highlighting the effectiveness of this technique
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
0.1
0.08
0.06
0.04
0.02
0
0 50 100 150 200 250
Histogram Equalization
Continuous case:
r
s T (r ) ( L 1) pr ( w)dw
0
Discrete values:
k
sk T (rk ) ( L 1) pr (rj )
j 0
k nj L 1 k
( L 1) nj k=0,1,..., L-1
j 0 MN MN j 0
8/21/2024 54
Example: Histogram Equalization
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096) has
the intensity distribution shown in following table.
Get the histogram equalization transformation function and give the p s(sk) for each
s k.
8/21/2024 55
Example: Histogram Equalization
0
s0 T (r0 ) 7 pr (rj ) 7 0.19 1.33 1
j 0
1
s1 T (r1 ) 7 pr (rj ) 7 (0.19 0.25) 3.08 3
j 0
s2 4.55 5 s3 5.67 6
s4 6.23 6 s5 6.65 7
s6 6.86 7 s7 7.00 7
8/21/2024 56
Example: Histogram Equalization
8/21/2024 57
Histogram Equalization
Here, the goal is to obtain a uniform histogram for the output image.
Some features of Histogram equalization are as follows:
• Spreading or flattening the histogram makes the dark pixels appear darker
and the light pixels appear lighter.
• Histogram equalization does not operate on the histogram itself but uses
the results of one histogram to transform the original image into an image
that will have equalized histogram.