Professional Documents
Culture Documents
Histogram
Dr.Eng. Ir. Wikky Fawwaz Al Maki, S.T., M.Eng., Dr. Ema Rahmawati
Image Enhancement
Basic of Histogram
Histogram Calculation
Histogram Equalization
– L: number of level
– pr(rk): probability the kth level occurs
– nk: number of occurrence of kth level
– n: total number of pixels in an image
6 11/02/2020 CIG4E3 / Pengolahan Citra Digital
Histogram
77 11/02/2020
11/02/2020 CIG4E3 / Pengolahan Citra Digital
BASIC OF HISTOGRAM
Example:
Image (left) has 256 distinct gray levels (8 bits)
Histogram (right) shows frequency (how many times) each gray level occurs
Helps avoid taking over‐exposed pictures
Also easier to detect types of processing p
reviously applied to image
E.g. K = 16, 10 pixels have
intensity value = 2
Histograms: only statistical
information
No indication of location of pixels
3 images below have same histogram
Half of pixels are gray, half are white
Same histogram = same statisics
Distribution of intensities could be different
Can we reconstruct image from histogram? No!
E.g. 8‐bit grayscale image,
Each histogram entry is defined as:
E.g:
Formal definition
Brightness of a grayscale image is the average intensity
of all pixels in image
The contrast of a grayscale image indicates how easily objects in
the image can be distinguished
High contrast image: many distinct intensity values
Low contrast: image uses few intensity values
Examples:
Michalson’s equation for contrast
These equations work well for simple images with 2
luminances (i.e. uniform foreground and background)
Does not work well for complex scenes with many
luminances orif min and max intensities are small
Difficult to increase image dynamic
range (e.g. interpolation)
HDR (12‐
14 bits) capture typical, then down‐
sample
Dynamic range in photographed scene may exceed number of
available bits to represent pixels
Solution:
Capture multiple images at different exposures
Combine them using image processing
Example: in GIF compression, dynamic range is reduced to only few intensities
(quantization)
Original Histogram
Example: Effect of JPEG
compression on line graphics
JPEG compression designed
for color images
Typically use equal sized bins
Bin size?
Example: To create 256 bins from 14‐bit
image
Discrete form
Uniform :
1
p s ( s ) pr ( r ) 1 r T 1 ( s ) 1 0 s 1
pr (r ) r T 1 ( s )
2 1.0 1.0
0.8
0.6
1 0.5
0.4
0.2
r r s
0 0 0
1 2 0.2 0.4 0.6 0.8 1.0 0.5 1.0
k nj k 0 rk 1
sk T (rk ) pr ( r j )
j 0 n j 0 k 0,1,..., L 1
1
rk T ( sk ) 0 sk 1
rk nk pr(rk)=nk/n 0,3
probability (p r (rk))
r1=1/7 1023 0,25 0,2
r7=1 81 0,02
34 11/02/2020 CIG4E3 / Pengolahan Citra Digital
Transformation function
0
s0 T (r0 ) pr (rj ) pr (r0 ) 0.19
j 0
1
s1 T (r1 ) pr (rj ) pr (r0 ) pr (r1 ) 0.44
j 0
2
s2 T (r2 ) pr (rj ) pr (r0 ) pr (r1 ) pr (r2 ) 0.65
j 0
3 4
s3 T (r3 ) pr (rj ) 0.81; s4 T (r4 ) pr (r j ) 0.89
j 0 j 0
5 6
s5 T (r5 ) pr (rj ) 0.95; s6 T (r6 ) pr (rj ) 0.98
j 0 j 0
7
s7 T (r7 ) pr (rj ) 1.00
j 0
1
transformed value (s k)
0,8
0,6
0,4
0,2
0
0 1/7 2/7 3/7 4/7 5/7 6/7 1
gray level (rk)
s0 = 0.19 1/7
s1 = 0.44 3/7
s2 = 0.65 5/7
s3 = 0.81 6/7
s4 = 0.89 6/7
s5 = 0.95 1
s6 = 0.98 1
s7 = 1.00 1
38 – r11/02/2020
5 (245 pixel),r6 (122 pixel),r7 (81 pixel) s4 = 7/7
CIG4E3 / Pengolahan Citra Digital
Uniform distribution?
probability (p r (rk))
0,2
r2=2/7 850 0,21
0,15
r3=3/7 656 0,16
0,1
r4=4/7 329 0,08
0,05
r5=5/7 245 0,06
0
r6=6/7 122 0,03 0 1/7 2/7 3/7 4/7 5/7 6/7 1
r7=1 81 0,02 gray level (rk)
probability (p z (z k))
0,25
z2=2/7 0,00
0,20
z3=3/7 0,15 0,15
z4=4/7 0,20 0,10
z5=5/7 0,30 0,05
probability (p s(sk))
0,2
r1s1=3/7 1023 0,25
0,15
r2s2=5/7 850 0,21
0,1
r3,r4 s3=6/7 985 0,24
0,05
r5,r6,r7 s4=7/7 448 0,11
0
0 1/7 2/7 3/7 4/7 5/7 6/7 1
gray level (sk)
v0 = G(z0) = 0,00
v1 = G(z1) = 0,00
v2 = G(z2) = 0,00
v3 = G(z3) = 0,15
v4 = G(z4) = 0,35
v5 = G(z5) = 0,65
v6 = G(z6) = 0,85
v7 = G(z7) = 1,00
48 11/02/2020 CIG4E3 / Pengolahan Citra Digital
Step 2: Find the transformation function
rk nk pr(rk)=nk/n Sk Sk x 7 Normal(Sk)
r0=0 790 0,19 0,19 1,33 1 s0=1/7
r1=1/7 1023 0,25 0,44 3,08 3 s1=3/7
r2=2/7 850 0,21 0,65 4,55 5 s2=5/7
r3=3/7 656 0,16 0,81 5,67 6 s3=6/7
r4=4/7 329 0,08 0,89 6,23 6 s4=6/7
r5=5/7 245 0,06 0,95 6,65 7 s5=7/7
r6=6/7 122 0,03 0,98 6,86 7 s6=7/7
r7=1 81 0,02 1,00 7 s7=1
49 11/02/2020 CIG4E3 / Pengolahan Citra Digital
Step 2: Find the transformation function
Perform histogram equalization to the desired histogram
zk pz(zk) Vk Vk x 7 Normal(Vk)
z0=0 0,00 0,00 0,00 v0=0
z1=1/7 0,00 0,00 0,00 v1=0
z2=2/7 0,00 0,00 0,00 v2=0
z3=3/7 0,15 0,15 1,05 1 v3=1/7
z4=4/7 0,20 0,35 2,45 2 v4=2/7
z5=5/7 0,30 0,65 4,45 4 v5=4/7
z6=6/7 0,20 0,85 5.95 6 v6=6/7
z7=1 0,15 1,00 7 v7=1
50 11/02/2020 CIG4E3 / Pengolahan Citra Digital
Graph of Transformation function
1,2
1
transformation (v k)
0,8
0,6
0,4
0,2
0
0 1/7 2/7 3/7 4/7 5/7 6/7 1
gray level (z k)
r0 = 0 z3 = 3/7
r1 = 1/7 z4 = 4/7
r2 = 2/7 z5 = 5/7
r3 = 3/7 z6 = 6/7
r4 = 4/7 z6 = 6/7
r5 = 5/7 z7 = 1
r6 = 6/7 z7 = 1
r7 = 1 z7 = 1
zk nk pz(zk)=nk/n 0,30
r0=0 0 0 0,25
probability (p z (z k))
r1=1/7 0 0 0,20
r2=2/7 0 0 0,15
0,10
r3=3/7 790 0,19
0,05
r4=4/7 1023 0,25
0,00
r5=5/7 850 0,21
0 1/7 2/7 3/7 4/7 5/7 6/7 1
r6=6/7 985 0,24 gray level (z k)
54
r7=1
11/02/2020
448 0,11 CIG4E3 / Pengolahan Citra Digital
Algorithm: 512 x 512 Image
Var x,y,i,minval,minj,j : integer; Histspec : array[0..255] of integer;
Invhist : array[0..255] of integer; Sum : real;
Begin
Hist_Equalization(Image) {equalisasi histogram}
For i:= 0 to 255 do {histogram yang dispesifikasikan telah disimpan di spec}
Sum:= 0.0;
For j:= 0 to i do Sum := sum + spec[j]
Histspec[i] = round(255 * sum)
Endfor {didapat fungsi transformasi}
for i:= 0 to 255 do {pemetaan histogram}
minval := abs(i – histspec[0]; minj := 0;
for j:= 0 to 255 do
if abs(i – histspec[j]) < minval then
minval := abs(i – histspec[j])
minj := j
endif
invhist[i]:= minj
endfor
endfor
for y:= 0 to 511 do {ubah nilai tiap pixel pada citra}
for x:= 0 to 511 do image[x,y] = invhist[image(x,y)]
559 11/02/2020
11/02/2020 CIG4E3 / Pengolahan Citra Digital
Local enhancement
Histogram equalization and specification : global (applied to all of
the pixels)
Sometimes we need an enhancement in specific area of the image