Histogram equalization

KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
1
IMAGE ENHANCEMENT - POINT
PROCESSING
KOM3212 Image Processing in Industrial
Systems
Some of the contents are adopted from
R. C. Gonzalez, R. E. Woods, Digital Image Processing, 2nd edition, Prentice Hall, 2008
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Today’s Lecture
• Image enhancement
Spatial domain Image Enhancement methods
Point-based methods
−
−
−
−
−
−
−
−
Negative
Log transformation
Power-law
Contrast stretching
Gray-level slicing
Bit plane slicing
Histogram equalization
Averaging
2
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Some basic Gray Level Transformations
• Image enhancement
Spatial domain Image Enhancement methods
Point-based methods
−
−
−
−
−
−
−
−
Negative
Log transformation
Power-law
Contrast stretching
Gray-level slicing
Bit plane slicing
Histogram equalization
Averaging
3
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
4
Intuitively
• Processing an image for visual interpretation is mostly referred as Image
Enhancement
• Visual evaluation of image quality is a highly subjective process
• Thus the definition of a good image is not always possible
• Human evaluation vs machine evaluation
• Performance of the algorithms has no clear-cuts
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
5
Spatial Domain
• The spatial domain refers to the aggregate of pixels composing an image
Spatial Domain
𝑓(0,0)
𝑓(𝑥𝑟 , 𝑦𝑐 )
Image 𝑓
g x, y = T f x, y
f x, y is the input image
g x, y is the output image
T[ ] is an operator on f x, y
s = T(r)
r is the set of gray levels
in input image
s is the set of gray levels
in input image
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
6
Different approaches for Image Enhancement
• Spatial domain
• Point-based processing (involved with gray levels of each pixel)
• Mask-based processing (neighbor-based processing, involved with
spatial filters related operations)
• Frequency domain
• Frequency domain filters
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Image Negatives
𝑠 = 𝑇(𝑟) = 𝐿 – 1 – 𝑟
7
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
8
Log transformation (Dynamic range compression)
𝑠 = 𝑇 𝑟 = 𝑐𝑙𝑜𝑔(1 + 𝑟 )
9
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Power-Law transformation
𝑠 = 𝑇 𝑟 = 𝑐𝑟 𝛾
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Power-Law transformation
10
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
11
Power-Law transformation - Gamma correction
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Contrast stretching
s  Tr   mr  b
12
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Gray-level slicing
𝑠=𝑇 𝑟 =
255 𝑖𝑓 𝐴 ≤ 𝑟 ≤ 𝐵
0
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
13
Highlighting an intensity range
14
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Bit-plane slicing
• Highlighting the contribution made by a specific bit.
• For pgm images, each pixel is represented by 8 bits.
• Each bit-plane is a binary image
8.Bit (msb) slice of the original image
8. bit slice
15
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
8. bit slice
7. bit slice
6. bit slice
5. bit slice
4. bit slice
3. bit slice
2. bit slice
1. bit slice
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Histogram Processing
• Image enhancement
1. Spatial domain methods
a) Point-based methods
− Negative
− Log transformation
− Power-law
− Contrast stretching
− Gray-level slicing
− Bit plane slicing
− Histogram equalization
− Averaging
16
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
17
Histogram
• Gray-level histogram is a function showing, for each gray
level, the number of pixels in the image that have that
gray level.
• Normalized histogram (probability):
• 𝑛𝑘 = ℎ 𝑟𝑘 =
• 𝑝𝑘 =
𝑛𝑘
𝑁
𝑓(𝑥,𝑦)=𝑟𝑘
1
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Dark
Image
Bright
Image
18
Low Cont
Image
Hight Cont.
Image
19
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Histogram - Examples
7000
6000
5000
4000
3000
2000
1000
0
-50
0
50
100
150
200
250
300
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Histogram equalization
Why and when do we want to use histogram Equalization?
s=T r
r = T −1 (s)
sk = T rk =
j=0..k
nj
=
N
pr (rj )
j=0..k
T(r) is single-valued and monotonically
increasing within range of r
T(r) has the same range as r [0, 1]
20
21
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Histogram equalization
• Transformation function
sk = T rk =
j=0..k
nj
=
N
pr (rj )
j=0..k
• pr(r) is the probability density function (pdf)
• The transformation function is the cumulative distribution function (CDF)
• To make the pdf of the transformed image uniform, i.e. to make the histogram
of the transformed image uniform
22
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Histogram equalization - Example
Calculate CDF according to gray levels
Gray Level Value
CDF
0
0.11
1
0.22
2
0.55
3
0.66
4
0.77
5
0.88
6
0.99
7
1
Gray Level Value
CDF
CDF * (Levels-1)
0
0.11
0
1
0.22
1
2
0.55
3
3
0.66
4
4
0.77
5
5
0.88
6
6
0.99
6
7
1
7
Then in this step you will multiply the
CDF value with (Gray levels -1)
Considering we have an 3 bpp image.
Then number of levels we have are 8.
And 1 subtracts 8 is 7. So we multiply
CDF by 7. Here what we got after
multiplying.
23
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Histogram equalization - Example
Gray Level Value
Frequency
0
2
1
4
2
6
3
8
4
10
5
12
6
14
7
16
Gray Level Value
New Gray Level Value
Frequency
0
0
2
1
1
4
2
3
6
3
4
8
4
5
10
5
6
12
6
6
14
7
7
16
if we map our new values to ,
then this is what we got.
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
24
Histogram equalization - Example
for (k=0;k<256;k++){
r[k]=0; // initializing the input image histogram function, giving 0 value to r[0]:r[256]
s[k]=0; // initializing the output image cumulative histogram function, giving 0 value to s[0]:s[256]
}
for (i=0; i<nr; i++)
for (j=0; j<nc; j++)
for (n=0; n<nchan; n++){
outimg(i,j,n)=inimg(i,j,n);
for (k=0;k<256;k++)
if (inimg(i,j,n)==k)
r[k]=r[k]+1; //calculating the input histogram values for each gray level r[0]:r[256]
}
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
25
Histogram equalization - Example
for (k=0;k<256;k++){
pr[k]=(float)r[k]/(nr*nc);
//calculating the input histogram probability function diving into total pixel number
}
for (k=0;k<256;k++){
for (j=0;j<k;j++)
s[k]=s[k]+pr[j]; // calculating the output image cumulative histogram function s[0]:s[256]
}
for (i=0; i<nr; i++)
for (j=0; j<nc; j++)
for (n=0; n<nchan; n++)
for (k=0;k<256;k++)
if (inimg(i,j,n)==k)
outimg(i,j,n)=round(255*s[k]);
// giving s gray level values instead of old r gray level values
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Histogram equalization
Dark
Image
Bright
Image
Low Cont
Image
Hight Cont.
Image
26
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Local enhancement
27
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Image Averaging
• Image enhancement
1. Spatial domain methods
a) Point-based methods
− Negative
− Log transformation
− Power-law
− Contrast stretching
− Gray-level slicing
− Bit plane slicing
− Histogram equalization
− Averaging
28
29
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
Image Averaging
original image f x, y
+
noisy image g x, y
noise η x, y
g x, y = f x, y + η x, y
M−1
M−1
g i x, y =
i=0
If the noise is uncorrelated and has
zero expectation, then the
expectation of g x, y will be f x, y
M−1
f x, y +
i=0
g x, y = f x, y + η x, y
η x, y
I=0
E g x, y
= f x, y
KOM3212 Image Processing in Industrial Systems | Dr Muharrem Mercimek
30
30
Image Averaging
• If the noise is uncorrelated and has zero expectation, then
Egx, y   f x, y 
1 2
σ g x, y   σ ηx, y 
M
2