Histogram Processing Histogram of a digital image with gray levels in the range [0,L-1] is a discrete function Where h(rk) = nk 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 1 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 2 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 3 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 scale. 4 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 higher than the others 5 Histogram Equalization an output image is obtained by mapping each pixel with level rk in the input image into a corresponding pixel with level sk in the output image 6 Example before after Histogram equalization 7 Example No. of pixels 6 2 3 3 2 4 2 4 3 4 3 2 3 5 3 4 2 2 4 2 4x4 image Gray scale = [0,9] 5 1 Gray level 0 1 2 3 4 5 6 7 8 9 histogram 8 Gray Level(j) No. of pixels 0 1 2 3 4 5 6 7 8 9 0 0 6 5 4 1 0 0 0 0 0 0 6 11 15 16 16 16 16 16 k n j 0 j k nj j 0 n s sx9 6 0 0 0 0 11 15 16 16 16 16 16 / / / / / / / / 16 16 16 16 16 16 16 16 3.3 3 6.1 6 8.4 8 9 9 9 9 9 9 Example No. of pixels 6 3 6 6 3 8 3 8 6 4 6 3 6 9 3 8 2 3 8 3 Output image Gray scale = [0,9] 5 1 0 1 2 3 4 5 6 7 8 9 Gray level Histogram equalization 10 Histogram Equalization Approach Fig: a) Original Image (b) Original Histogram (c) Equalized Histogram (d) Enhanced Image 11 Image Enhancement by Histogram Modification Technique For gray levels that assume discrete values, we deal with probabilities given by the relation nk p r (rk ) n 0 = rk= 1 k=0,1,…..L-1, ---------- (10) Where L is number of levels, pr(rk) is the probability of the kth gray level, nk is the total number of times this level appears in the image , and n is called the total number of pixels in the image. 12 A plot of pr (rk) versus rk is usually called a histogram, and the technique used for obtaining a uniform histogram is known as histogram equalization or histogram linearization. The discrete form of equalization techniques given by the relation k nj j 0 n s k T (rk ) 13 Example: suppose that a 64*64, 8-levels image has the graylevel distribution shown in table 1. The histogram of these gray levels is shown in fig.3(a) Table (1) rk r0 = 0 nk 790 1023 Pr(rk) = nk/n 0.19 0.25 850 0.21 656 0.16 329 0.08 245 0.06 122 0.03 81 0.2 r1=1/7 r2=2/7 r3=3/7 r4=4/7 r5=5/7 r6=6/7 r7=1 14 Figure No.3 Illustrated of the histogram –equalization method (a) Original Histogram (b) Transformation function (c) Equalization Histogram. 15 The transformation function is obtained by using Eq. (8). For instance. 0 s o T (ro ) p r (r j ) j 0 =pr(r0) =0.19 Similarly, 1 s1 T (r1 ) pr (rj ) j 0 =pr(r0) + pr(r1) =0.44 And ` s2=0.65 s3=0.81 s4=0.89 s5=0.95 s6=0.98 s7=1.00 16 The in formation function has form shown in fig.3 (b). Since only eight equally spaced levels are allowed in this case, each of the transformed values must be assigned to its closest valid level. Thus we have s0=1/7 s4=6/7 s1=3/7 s5=1 s2=5/7 s6=1 s3=6/7 s7=1 It is noted that there only five distinct histogram-equalization gray levels. Redefining the notation to take this into account yields the levels s0=1/7 s4=1 s1=3/7 s2=5/7 s3=6/7 17 Since ro=0 was mapped to s o =1/7, there are 790 transformed pixels with this new value . Also there are 1023 pixels with value s1 =3/7and 850 pixels with value s2 = 5/7 How ever , since both levels r3and r4 were mapped to s3 = 6/7 , there are now 656+122=81=985 pixels with this new value. Similarly, there are 245 + 122 +81 = 448 pixels with value s4 =1 .Dividing these numbers by n= 4096 yield the histogram shown in Fig.3(c) . Since a histogram is an approximation to a probability density function, perfecting flat results are seldom obtained when working with discrete levels. 18