Histogram and Its Processing -...

21
Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová 2004

Transcript of Histogram and Its Processing -...

Page 1: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Histogramand Its Processing

3rd Lectureon Image Processing

Martina Mudrová 2004

Page 2: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Definition

What a histogram is?

= vector of absolute numbers occurrence of every colour in the picture[H(1),H(2),…H(c)]

• 1 vector H is used for intensity images• 3 vectors H1,H2,H3 are used in case of colour pictures (for R,G,B components,

each of them is processed separatelly according to the same scheme)

c ≤ m.n c…number of coloursm,n…image size∑

=

=c

inmiH

1.)(

2M. Mudrová, 2004

Page 3: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

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

0 0 . 1 0 . 2 0 . 3 0 . 4 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 1

0

2

4

6

8

1 0

1 2

1 4

3M. Mudrová, 2004

Page 4: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Another Ways to Histogram Expression

• normalizing the range of x-axis to the <0,1>• displaying a cumulative sum of histogram values

4M. Mudrová, 2004

Page 5: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Histogram Use I

• histogram provides basic information about brightness level in the picture– further histogram processing can improve picture quality

0 50 100 150 200 250

0

1000

2000

3000

4000

5000

6000

7000

8000

0 50 100 150 200 250

0

0.5

1

1.5

2

2.5x 104

0 50 100 150 200 2500

500

1000

this picture has very low level of contrast- histogram bars are only in the middle part

this picture is too bright-histogram bars are almost in the upper part

this picture is too dark-histogram bars are almost in the low part

5M. Mudrová, 2004

Page 6: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Histogram Use II

• enables threshold level T selection for picture colour reduction- especially in case of bimodal histogram- application in the shape recognition, granulometry,…

yL pro x TH pro x T

=<≥

⎧⎨⎩

x… input intensityy… new intensityT… threshold level

6M. Mudrová, 2004

Page 7: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Histogram Use III

• serves for cameras calibration

– there are taken the pictures with known histogram, the comparison of given and obtained histogram serves for settingsof camera parameters

Example of testing picture used for cameras calibrations and tests

7M. Mudrová, 2004

Page 8: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Histogram Equalization

What do I mean by this?

• Make a histogram as flat as is possible

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

1000

2000

3000

4000

5000 Real picture histogram

Ideal histogram

• The algorithm of equalization is based on statistical methods:

D … the optimal intensity valuen,m ... Image size (in pixels)MAX... Maximal intensity value MAX

mnD .=

8M. Mudrová, 2004

Page 9: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Example of Histogram Equalization

Original Image Image after histogram equalizationoriginal po ekvalizaci.

0 0 . 1 0 . 2 0 . 3 0 . 4 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 1

0

1 0 0 0

2 0 0 0

3 0 0 0

4 0 0 0

5 0 0 0

h i s t o g r a m

0 0 . 1 0 . 2 0 . 3 0 . 4 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 1

0

1 0 0 0

2 0 0 0

3 0 0 0

4 0 0 0

5 0 0 0

0 5 0 1 0 0 1 5 0 2 0 0 2 5 0 3 0 00

2

4

6

8

1 0x 1 0 4

0 5 0 1 0 0 1 5 0 2 0 0 2 5 0 3 0 00

2

4

6

8

1 0x 1 0 4 k u m u l a c e c a r

9M. Mudrová, 2004

Page 10: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Histogram Adjustment

What happens if I change the histogram bars position?

0 1l h

b t

y = xγ

0 1

1. Shifting the histogram2. Stretching the histogram

A. Linear correction: g = 1

B. Non-Linear correction: g <> 1

x…input histogram

y…output histogram

Gamma correction

00.20.40.60.8

1

0 0.2 0.4 0.6 0.8 1

input value x

outp

ut v

alue

yg=0.5g=2

10M. Mudrová, 2004

Page 11: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Shifting Histogram Bars to the Right

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

• Increasing the brightness shifts the histogram to the right (towards white).

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

11M. Mudrová, 2004

Page 12: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Shifting the Histogram Bars to the Left

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

• Decreasing the brightness shifts the histogram to the left (towards black).

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

12M. Mudrová, 2004

Page 13: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Another Possibility of Brightness Control ?

Can I simple add any constant to every pixel’s value?original original+0.3

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

1000

2000

3000

4000

5000

6000

his togram po uprave

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

1000

2000

3000

4000

5000

6000

7000

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

1000

2000

3000

4000

5000

6000

7000

his togram originalu

! This way can lead to the destroying of “highlight” detailswithout possibility of their recovering by means of following histogram operations

13M. Mudrová, 2004

Page 14: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Loosing Shadow Details

Can I simple subtract any constant to every pixel’s value?

14

! This way can lead to the destroying of “shadow” detailswithout possibility of their recovering by means of following histogram operations

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

1000

2000

3000

4000

5000

6000

7000

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

1000

2000

3000

4000

5000

6000

7000

8000

9000

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0

1000

2000

3000

4000

5000

6000

7000

8000

9000

M. Mudrová, 2004

Page 15: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Histogram Dilatation and Stretching - Contrast

0 0 . 1 0 . 2 0 . 3 0 . 4 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 1

0

1 0 0 0

2 0 0 0

3 0 0 0

4 0 0 0

5 0 0 0

6 0 0 0

7 0 0 0

8 0 0 0

9 0 0 0

0 0 .1 0 . 2 0 . 3 0 .4 0 . 5 0 .6 0 . 7 0 . 8 0 .9 1

0

5 0 0

1 0 0 0

1 5 0 0

2 0 0 0

2 5 0 0

3 0 0 0

3 5 0 0

4 0 0 0

4 5 0 0

5 0 0 0

0 0 . 1 0 . 2 0 . 3 0 . 4 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 1

0

1 0 0 0

2 0 0 0

3 0 0 0

4 0 0 0

5 0 0 0

6 0 0 0

7 0 0 0

15

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á, 2004

Page 16: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Gamma Correction

0 1l h

b t

y = x γ

0 1

x…input histogram

γxy =0<γ <1…a picture becomes lighterγ >1… a picture becomes darker γ =1…linear correction

y…output histogram

Gamma correction

00.20.4

0.60.8

1

0 0.2 0.4 0.6 0.8 1

input value x

outp

ut v

alue

y

g=0.5

g=2

! Some digital cameras work accordingto another equation:

γ1

xy =16

M. Mudrová, 2004

Page 17: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Gamma Correction Use

Histogram Adjustment Parameters

Image Histogram

0 0 . 5 1

0

2 0

4 0

6 0

8 0

original image

0 0 5 10

5 0shifting histogram bars from<0.25,1> to <0, 0.75>, γ =1

0 0 . 5 10

2 0

4 0

6 0

8 0

shifting histogram bars form<0.25,1> to <0, 0.75>, γ =5

0 0 2 0 4 0 6 0 8 10

50

17

shifting histogram bars from<0.25,1> to <0, 0.75>, γ =0.2

M. Mudrová, 2004

Page 18: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

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á, 2004

Page 19: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Matlab Commands for Histogram Operation

imhist

histeq

imadjust

(brighten)

(contrast)

stretchlim

19M. Mudrová, 2004

Page 20: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Example

Histogram Equalizationoriginal

0 100 2000

2000

4000

histogram originalu

po ekvalizaci.

0 100 2000

2000

4000

histogram

0 100 200 3000

5

10x 104 kumulace car

0 100 200 3000

5

10x 104

% Image Adjustment (1)% Histogram Equalization

cleardelete(get(0,'children'));

[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)))

20M. Mudrová, 2004

Page 21: Histogram and Its Processing - vscht.czuprt.vscht.cz/mudrova/ip/lectures/03-HISTOGRAM/Histogramen.pdf · Histogram and Its Processing 3rd Lecture on Image Processing Martina Mudrová

Example

Linear Histogram AdjustmentOriginal Image Histogram of Original Image% Histogram adjustment (2)

cleardelete(get(0,'children'))

figure(1)[x,map]=imread('../busek.bmp');i=ind2gray(x,map); j=imadjust(i,[0 1],[0 0.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')

21M. Mudrová, 2004

0 100 2000

2000

4000

6000

Histogram of Modified ImageModified Image

0 100 2000

2000

4000