24
1 It it T f ti Digital Image Processing Intensity Transformations (Histogram Processing) Christophoros Niko University of Ioannina - Department of Computer Science Christophoros Nikou [email protected] 2 Contents Over the next few lectures we will look at image enhancement techniques working in the spatial domain: – Histogram processing – Spatial filtering – Neighbourhood operations C. Nikou – Digital Image Processing (E12)

Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

1

I t it T f ti

Digital Image Processing

Intensity Transformations(Histogram Processing)

Christophoros Niko

University of Ioannina - Department of Computer Science

Christophoros [email protected]

2 Contents

Over the next few lectures we will look at image enhancement techniques working in g q gthe spatial domain:

– Histogram processing– Spatial filtering – Neighbourhood operations

C. Nikou – Digital Image Processing (E12)

Page 2: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

2

3 Image Histograms

The histogram of an image shows us the distribution of grey levels in the imageg y gMassively useful in image processing, especially in segmentation

enci

es

C. Nikou – Digital Image Processing (E12)

Grey Levels

Freq

ue

4 Histogram Examples

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 3: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

3

5 Histogram Examples (cont…)g

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

6 Histogram Examples (cont…)

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 4: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

4

7 Histogram Examples (cont…)g

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

8 Histogram Examples (cont…)

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 5: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

5

9 Histogram Examples (cont…)g

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

10 Histogram Examples (cont…)

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 6: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

6

11 Histogram Examples (cont…)g

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

12 Histogram Examples (cont…)

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 7: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

7

13 Histogram Examples (cont…)g

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

14 Histogram Examples (cont…)

• A selection of images and their histogramsg

(200

2)

g• Notice the relationships

between the images and their histograms

• Note that the high contrast

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

image has the most evenly spaced histogram

Imag

es ta

ken

from

Gon

zale

z &

Page 8: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

8

15 Contrast Stretching

• We can fix images that have poor contrast by applying a pretty simple contrast y pp y g p y pspecification

• The interesting part is how do we decide on this transformation function?

C. Nikou – Digital Image Processing (E12)

16 Histogram Equalisation

• Spreading out the frequencies in an image (or equalising the image) is a simple way to improve dark or washed out images.

• At first, the continuous case will be studied:– r is the intensity of the image in [0, L-1].– we focus on transformations s=T(r):• T(r) is strictly monotonically increasing.

C. Nikou – Digital Image Processing (E12)

T(r) is strictly monotonically increasing.• T(r) must satisfy:

0 ( ) 1, 0 1T r L for r L≤ ≤ − ≤ ≤ −

Page 9: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

9

17 Histogram Equalisation (cont...)

• The condition for T(r) to be monotonically increasing guarantees that ordering of the

t t i t it l ill f ll th d ioutput intensity values will follow the ordering of the input intensity values (avoids reversal of intensities).

• If T(r) is strictly monotonically increasing then the mapping from s back to r will be 1-1.

C. Nikou – Digital Image Processing (E12)

• The second condition (T(r) in [0,1]) guarantees that the range of the output will be the same as the range of the input.

18 Histogram Equalisation (cont...)

C. Nikou – Digital Image Processing (E12)

a) We cannot perform inverse mapping (from s to r).b) Inverse mapping is possible.

Page 10: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

10

19 Histogram Equalisation (cont...)

• We can view intensities r and s as random variables and their histograms as probability g p ydensity functions (pdf) pr(r) and ps(s).

• Fundamental result from probability theory:– If pr(r) and T(r) are known and T(r) is

continuous and differentiable, then

C. Nikou – Digital Image Processing (E12)

1( ) ( ) ( )s r rdrp s p r p r

ds dsdr

= =

20 Histogram Equalisation (cont...)

• The pdf of the output is determined by the pdf of the input and the transformation.p p

• This means that we can determine the histogram of the output image.

• A transformation of particular importance in image processing is the cumulative

C. Nikou – Digital Image Processing (E12)

distribution function (CDF) of a random variable:

0

( ) ( 1) ( )r

rs T r L p w dw= = − ∫

Page 11: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

11

21 Histogram Equalisation (cont...)

• It satisfies the first condition as the area under the curve increases as r increases.

• It satisfies the second condition as for r=L-1we have s=L-1.

• To find ps(s) we have to compute

C. Nikou – Digital Image Processing (E12)

dsdr 0

( 1) ( )r

rdL p w dwdr

= − ∫ ( 1) ( )rL p r= −( )dT rdr

=

22 Histogram Equalisation (cont...)

Substituting this result:ds

to

( ) ( )s rdrp s p rds

=

( 1) ( )rds L p rdr

= −

Uniform pdf

C. Nikou – Digital Image Processing (E12)

yields

ds

1( ) ( )( 1) ( )s r

r

p s p rL p r

=−

1 , 0 11

s LL

= ≤ ≤ −−

Page 12: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

12

23 Histogram Equalisation (cont...)

The formula for histogram equalisation in the discrete case is given

where• rk: input intensity• sk: processed intensity

0( ) ( 1) ( )

k

k k r jj

s T r L p r=

= = − ∑0

( 1) k

jj

L nMN =

−= ∑

C. Nikou – Digital Image Processing (E12)

k p y• nj: the frequency of intensity j• MN: the number of image pixels.

24Histogram Equalisation (cont...)

ExampleA 3-bit 64x64 image has the following intensities:

k

Applying histogram equalization:

0( ) ( 1) ( )

k

k k r jj

s T r L p r=

= = − ∑

C. Nikou – Digital Image Processing (E12)

y g g0

0 0 00

( ) 7 ( ) 7 ( ) 1.33r j rj

s T r p r p r=

= = = =∑1

1 1 0 10

( ) 7 ( ) 7 ( ) 7 ( ) 3.08r j r rj

s T r p r p r p r=

= = = + =∑

Page 13: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

13

25Histogram Equalisation (cont...)

ExampleRounding to the nearest integer:

0 1 2 31.33 1 3.08 3 4.55 5 5.67 6s s s s= → = → = → = →0 1 2 3

4 5 6 76.23 6 6.65 7 6.86 7 7.00 7s s s s= → = → = → = →

C. Nikou – Digital Image Processing (E12)

26Histogram Equalization (cont…)

ExampleNotice that due to discretization, the resulting histogram will rarely be perfectly flat. However, it

g (2

002)

will be extended.

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 14: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

14

27 Equalisation Transformation Functiong

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

28 Equalisation Examples

g (2

002)

1

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 15: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

15

29 Equalisation Transformation Functions

The functions used to equalise the images in the previous exampleg

(200

2)

p p

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

30 Equalisation Examples

g (2

002)

2

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 16: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

16

31 Equalisation Transformation Functions

The functions used to equalise the images in the previous exampleg

(200

2)

p p

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

32 Equalisation Examples (cont…)

g (2

002) 3

& W

oods

, Dig

ital I

mag

e P

roce

ssin

4

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 17: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

17

33 Equalisation Transformation Functions

The functions used to equalise the images in the previous examplesg

(200

2)

p p

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

34 Histogram Specification

• Histogram equalization does not always provide the desirable results.

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

• Image of Phobos (Mars moon) and its histogram.• Many values near zero in the initial histogram

Page 18: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

18

35 Histogram Specification (cont...)g

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Histogram equalization

36 Histogram specification (cont.)

• In these cases, it is more useful to specify the final histogram. g

(200

2)

g• Problem statement:

– Given pr(r) from the image and the target histogram pz(z), estimate the transformation z=T(r).

Th l ti l it hi t li ti& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

• The solution exploits histogram equalization.

Imag

es ta

ken

from

Gon

zale

z &

Page 19: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

19

37 Histogram specification (cont…)

•Equalize the initial histogram of the image:

g (2

002)

( ) ( 1) ( )r

s T r L p w dw= = − ∫•Equalize the target histogram:

•Obtain the inverse transform:I ti f l f i th i&

Woo

ds, D

igita

l Im

age

Pro

cess

in

0

( ) ( 1) ( )rs T r L p w dw∫

0

( ) ( 1) ( )r

zs G z L p w dw= = − ∫1( )z G s−= 1( ( ))G T r−=

( ) ( )G z T r=

C. Nikou – Digital Image Processing (E12)

In practice, for every value of r in the image:• get its equalized transformation s=T(r).• perform the inverse mapping z=G-1(s), where s=G(z) is the equalized target histogram.

Imag

es ta

ken

from

Gon

zale

z &

38 Histogram specification (cont…)

The discrete case:

g (2

002)

•Equalize the initial histogram of the image:

•Equalize the target histogram:

& W

oods

, Dig

ital I

mag

e P

roce

ssin

0( ) ( 1) ( )

k

k k r jj

s T r L p r=

= = − ∑( ) ( )G z T r=

0

( 1) k

jj

L nMN =

−= ∑

( ) ( 1) ( )q

G L ∑

C. Nikou – Digital Image Processing (E12)

•Obtain the inverse transform:

Imag

es ta

ken

from

Gon

zale

z &

1( )q kz G s−= 1( ( ))kG T r−=

0

( ) ( 1) ( )k q z ii

s G z L p r=

= = − ∑

Page 20: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

20

39Histogram Specification (cont...)

ExampleConsider again the 3-bit 64x64 image:

It is desired to transform this histogram to:

C. Nikou – Digital Image Processing (E12)

g

with

0 1 2 3

4 5 6 7

( ) 0.00 ( ) 0.00 ( ) 0.00 ( ) 0.15( ) 0.20 ( ) 0.30 ( ) 0.20 ( ) 0.15

z z z z

z z z z

p z p z p z p zp z p z p z p z

= = = == = = =

0 1 2 3 4 5 6 70, 1, 2, 3, 4, 5, 6, 7.z z z z z z z z= = = = = = = =

40Histogram Specification (cont...)

ExampleThe first step is to equalize the input (as before):

0 1 2 3 4 5 6 71, 3, 5, 6, 6, 7, 7, 7s s s s s s s s= = = = = = = =

The next step is to equalize the output:

0 1 2 3 4 5 6 7

0 1 2 3

4 5 6 7

( ) 0 ( ) 0 ( ) 0 ( ) 1( ) 2 ( ) 5 ( ) 6 ( ) 7

G z G z G z G zG z G z G z G z

= = = == = = =

C. Nikou – Digital Image Processing (E12)

Notice that G(z) is not strictly monotonic. We must resolve this ambiguity by choosing, e.g. the smallest value for the inverse mapping.

Page 21: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

21

41Histogram Specification (cont...)

ExamplePerform inverse mapping: find the smallest value of zq that is closest to sk:

0 0

1 1

2 2

3 3

( ) ( )1 ( ) 03 ( ) 05 ( ) 06 ( ) 16 ( ) 2

k i qs T r G zs G zs G zs G zs G z

G

== == == == =

k qs z→

1 3→

3 4→

5 5→

C. Nikou – Digital Image Processing (E12)

4 4

5 5

6 6

7 7

6 ( ) 27 ( ) 57 ( ) 67 ( ) 7

s G zs G zs G zs G z

= == == == =

6 6→

7 7→e.g. every pixel with value s0=1 in the histogram-equalized image would have a value of 3 (z3) in the histogram-specified image.

42Histogram Specification (cont...)

ExampleNotice that due to discretization, the resulting histogram will rarely be exactly the same as the

g (2

002)

desired histogram.

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Page 22: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

22

43 Histogram Specification (cont...)g

(200

2)&

Woo

ds, D

igita

l Im

age

Pro

cess

in

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Histogram equalizationOriginal image

44 Histogram Specification (cont...)

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Histogram equalization

Page 23: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

23

45 Histogram Specification (cont...)g

(200

2)

Specified histogram

& W

oods

, Dig

ital I

mag

e P

roce

ssin

Transformation function and its inverse

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Resulting histogram

46 Local Histogram Processing

g (2

002)

& W

oods

, Dig

ital I

mag

e P

roce

ssin

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

• Image in (a) is slightly noisy but the noise is imperceptible.• HE enhances the noise in smooth regions (b).• Local HE reveals structures having values close to the values of the

squares and small sizes to influence HE (c).

Page 24: Digital Image Processingcnikou/Courses/Digital_Image_Processing/... · 2011. 3. 8. · 2 3 Image Histograms The histogram of an image shows us the distribution of ggy grey levels

24

47 Summary

We have looked at:– Different kinds of image enhancementDifferent kinds of image enhancement– Histograms– Histogram equalisation– Histogram specification

Next time we will start to look at spatial

C. Nikou – Digital Image Processing (E12)

filtering and neighbourhood operations