Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová 24
Definition What a histogram is? = vector of absolute numbers occurrence of every colour in the picture [H(1),H(2), H(c)] c m.n c c number of colours m,n image size i= 1 H ( i) 1 vector H is used for intensity images 3 vectors H 1,H 2,H 3 are used in case of colour pictures (for R,G,B components, each of them is processed separatelly according to the same scheme) = m. n M. Mudrová, 24 2
Histogram Properties histogram is a statistical value describing the probability of occurency each colour it says nothing about colour layout in the picture Two different pictures: Histogram both of them bimodal 1 4 1 2 1 8 6 4 2 M. Mudrová, 24. 1. 2. 3. 4. 5. 6. 7. 8. 9 1 3
Another Ways to Histogram Expression normalizing the range of x-axis to the <,1> displaying a cumulative sum of histogram values 4 M. Mudrová, 24
Histogram Use I histogram provides basic information about brightness level in the picture further histogram processing can improve picture quality 8 2.5 x 14 7 6 2 1 5 1.5 4 3 1 5 2 1.5 5 1 15 2 25 this picture is too bright -histogram bars are almost in the upper part 5 1 15 2 25 this picture is too dark -histogram bars are almost in the low part 5 1 15 2 25 this picture has very low level of contrast - histogram bars are only in the middle part 5 M. Mudrová, 24
Histogram Use II enables threshold level T selection for picture colour reduction - especially in case of bimodal histogram - application in the shape recognition, granulometry, L pro x< T y= H pro x T x input intensity y new intensity T threshold level 6 M. Mudrová, 24
Histogram Use III serves for cameras calibration there are taken the pictures with known histogram, the comparison of given and obtained histogram serves for settings of camera parameters Example of testing picture used for cameras calibrations and tests 7 M. Mudrová, 24
Histogram Equalization What do I mean by this? Make a histogram as flat as is possible 5 4 3 Real picture histogram Ideal histogram 2 1.1.2.3.4.5.6.7.8.9 1 The algorithm of equalization is based on statistical methods: D = n. m MAX D the optimal intensity value n,m... Image size (in pixels) MAX... Maximal intensity value 8 M. Mudrová, 24
Example of Histogram Equalization Original Image original Image after histogram equalization po ekvalizaci. 5 5 histogram 4 4 3 3 2 2 1 1 1.1.2.3.4.5.6.7.8.9 1 x 1 4 k u m u la c e c a r.1.2.3.4.5.6.7.8.9 1 1 x 1 4 8 8 6 6 4 2 5 1 1 5 2 2 5 3 4 2 5 1 15 2 25 3 9 M. Mudrová, 24
Histogram Adjustment What happens if I change the histogram bars position? x input histogram l h 1 A. Linear correction: g = 1 1. Shifting the histogram 2. Stretching the histogram B. Non-Linear correction: g <> 1 y = x γ b t 1 y output histogram output value y 1.8.6.4.2 Gamma correction.2.4.6.8 1 g=.5 g=2 input value x 1 M. Mudrová, 24
Shifting Histogram Bars to the Right Increasing the brightness shifts the histogram to the right (towards white). 5 45 4 35 3 25 2 15 1 5 5 45 4 35 3 25 2 15 1 5 5 45 4 35 3 25 2 15 1 5.1.2.3.4.5.6.7.8.9 1.1.2.3.4.5.6.7.8.9 1.1.2.3.4.5.6.7.8.9 1 11 M. Mudrová, 24
Shifting the Histogram Bars to the Left Decreasing the brightness shifts the histogram to the left (towards black). 5 45 4 35 3 25 2 15 1 5.1.2.3.4.5.6.7.8.9 1 5 45 4 35 3 25 2 15 1 5.1.2.3.4.5.6.7.8.9 1 5 45 4 35 3 25 2 15 1 5.1.2.3.4.5.6.7.8.9 1 12 M. Mudrová, 24
Another Possibility of Brightness Control? Can I simple add any constant to every pixel s value? original original+.3 histogram originalu histogram po uprave 7 7 6 5 4 3 2 1 6 5 4 3 2 1 6 5 4 3 2 1.1.2.3.4.5.6.7.8.9 1.1.2.3.4.5.6.7.8.9 1.1.2.3.4.5.6.7.8.9 1! This way can lead to the destroying of highlight details without possibility of their recovering by means of following histogram operations M. Mudrová, 24 13
Loosing Shadow Details Can I simple subtract any constant to every pixel s value? 7 6 5 9 8 7 9 8 7 6 4 5 3 4 2 3 2 1 1.1.2.3.4.5.6.7.8.9 1.1.2.3.4.5.6.7.8.9 1 6 5 4 3 2 1.1.2.3.4.5.6.7.8.9 1! This way can lead to the destroying of shadow details without possibility of their recovering by means of following histogram operations M. Mudrová, 24 14
Histogram Dilatation and Stretching - Contrast 7 6 5 4 3 2 1.1.2.3.4.5.6.7.8.9 1 9 8 7 6 5 4 3 2 1.1.2.3.4.5.6.7.8.9 1 5 45 4 35 3 25 2 15 1 5.1.2.3.4.5.6.7.8.9 1 Histogram dilatation causes contrast increasing Histogram stretching causes contrast decreasing! Be careful about loosing shadow and highlight details during the histogram dilatation, any following histogram stretching can not recover them information can be beyond redemption M. Mudrová, 24 15
Gamma Correction x input histogram y = x γ l h 1 y = x γ <γ <1 a picture becomes lighter γ >1 a picture becomes darker γ =1 linear correction b t 1 y output histogram Gamma correction output value y 1.8.6.4.2.2.4.6.8 1 input value x g=.5 g=2! Some digital cameras work according to another equation: y = x 1 γ 16 M. Mudrová, 24
Gamma Correction Use Histogram Adjustment Parameters Image 8 Histogram 6 original image 4 2. 5 1 shifting histogram bars from <.25,1> to <,.75>, γ =1 shifting histogram bars form <.25,1> to <,.75>, γ =5 5 5 1 8 6 4 2. 5 1 shifting histogram bars from <.25,1> to <,.75>, γ =.2 M. Mudrová, 24 5 2 4 6 8 1 17
Advanced Histogram Operations - Operations with a LUT (Look-up table) -1 new color bar is assigned to 1,2 or more original colors - non-inversible operation - is used for interesting artificial (artistic) effects (substitution of water colour paintingf from realistic photos ) - New histogram with another shape can be imposed to the original picture - 18 M. Mudrová, 24
Matlab Commands for Histogram Operation imhist histeq imadjust (brighten) (contrast) stretchlim 19 M. Mudrová, 24
Example Histogram Equalization % Image Adjustment (1) % Histogram Equalization clear delete(get(,'children')); original po ekvalizaci. [x,map]=imread('busek.bmp'); i=ind2gray(x,map); subplot(321), imshow(i) title('original') subplot(323),imhist(i) title('histogram originalu'), j=histeq(i,32); subplot(322), subimage(j ) axis off,title('po ekvalizaci.') subplot(324),imhist(j) title('histogram '), subplot(325),plot(cumsum(imhist(i))) title('kumulace car'), subplot(326),plot(cumsum(imhist(j))) 4 2 5 histogram originalu 1 2 1 x 14 kumulace car 1 2 3 4 2 5 histogram 1 2 1 x 14 1 2 3 2 M. Mudrová, 24
Example Linear Histogram Adjustment % Histogram adjustment (2) Original Image Histogram of Original Image clear delete(get(,'children')) figure(1) [x,map]=imread('../busek.bmp'); i=ind2gray(x,map); j=imadjust(i,[ 1],[.8],1); subplot(221),imshow(i) title('original') subplot(222),imhist(i,128) title('histogram originalu') subplot(223),imshow(j) title(' po uprave') subplot(224),imhist(j) title('histogram po uprave') Modified Image 6 4 2 1 2 Histogram of Modified Image 4 2 1 2 21 M. Mudrová, 24