0% found this document useful (0 votes)
114 views

Digital Image Processing: Lecture # 4 Histogram Equalization & Matching

Histogram equalization is a method to remap the intensity values of pixels in an image so that the output image has a uniform distribution of intensities. It does this by using the cumulative distribution function (CDF) of the input image as a lookup table for mapping intensity values to output values. Specifically, each pixel value in the input image is mapped to a new value based on the CDF value at that intensity. This mapping spreads out the most frequent intensity values in the image. The result is an output image that uses a wider range of tonal values and has a CDF that is almost flat, indicating an equal probability of all intensity values.

Uploaded by

Match Maker
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

Digital Image Processing: Lecture # 4 Histogram Equalization & Matching

Histogram equalization is a method to remap the intensity values of pixels in an image so that the output image has a uniform distribution of intensities. It does this by using the cumulative distribution function (CDF) of the input image as a lookup table for mapping intensity values to output values. Specifically, each pixel value in the input image is mapped to a new value based on the CDF value at that intensity. This mapping spreads out the most frequent intensity values in the image. The result is an output image that uses a wider range of tonal values and has a CDF that is almost flat, indicating an equal probability of all intensity values.

Uploaded by

Match Maker
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Digital Image Processing

Lecture # 4
Histogram Equalization & Matching

1
Histogram Equalization

Histogram equalization re-assigns the intensity values of pixels in the input


image such that the output image contains a uniform distribution of intensities

2
HISTOGRAM EQUALIZATION

3
AERIAL PHOTOGRAPH OF THE PENTAGON

Resulting image uses more of dynamic range.


4
Resulting histogram almost, but not completely, flat.
The Probability Distribution Function
of an Image
255
Let A   hI  g 
g 0

Note that since hI  g  is the number of pixels in


I with value g ,
A is the number of pixels in I . That is if I is
R rows by C columns then A  R  C.

Then, This is the probability


1 that an arbitrary pixel
pI  g   hI  g 
A from I has value g.

5
The Probability Distribution Function
of an Image

• p(g) is the fraction of pixels in an image that have


intensity value g.
• p(g) is the probability that a pixel randomly selected
from the given image has intensity value g.
• Whereas the sum of the histogram h(g) over all g from
0 to 255 is equal to the number of pixels in the image,
the sum of p(g) over all g is 1.
• p is the normalized histogram of the image

6
The Cumulative Distribution Function
of an Image
Let q = I(r,c) be the value of a randomly
selected pixel from I. Let g be a specific gray
level. The probability that q ≤ g is given by

g
1 g
 h  
I

PI  g    pI      hI    0
255
,
 h  
 0 A  0
I

0

where hI(γ ) is
the histogram of This is the probability that
image I. any given pixel from I has
value less than or equal to g.

7
The Cumulative Distribution Function
of an Image
Let q = I(r,c) be the value of a randomly
selected pixel from I. Let g be a specific gray Also called CDF
level. The probability that q ≤ g is given by for “Cumulative
Distribution
Function”.
g

g
1 g
 h  
I

PI  g    pI      hI    0
255
,
 h  
 0 A  0
I

0

where hI(γ ) is
the histogram of This is the probability that
image I. any given pixel from I has
value less than or equal to g.

8
The Cumulative Distribution Function
of an Image
• P(g) is the fraction of pixels in an image that have intensity
values less than or equal to g.
• P(g) is the probability that a pixel randomly selected from
the given band has an intensity value less than or equal to
g.
• P(g) is the cumulative (or running) sum of p(g) from 0
through g inclusive.
• P(0) = p(0) and P(255) = 1;

9
Histogram Equalization

Task: remap image I so that its histogram is as close to


constant as possible

Let PI   
be the cumulative (probability) distribution function of I.

The CDF itself is used as the LUT.

10
Histogram Equalization
The CDF (cumulative
distribution) is the
pdf
LUT for remapping.

CDF

11
Histogram Equalization
The CDF (cumulative
distribution) is the
pdf
LUT for remapping.

LUT

12
Histogram Equalization
The CDF (cumulative
distribution) is the
pdf
LUT for remapping.

LUT

13
Histogram Equalization

14
Histogram Equalization
Luminosity

before

J  r , c   255  PI  I  r , c   .
after

15
HISTOGRAM EQUALIZATION
IMPLEMENTATION

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

Gray levels 0 1 2 3 4 5 6 7 8 9
Counts (h(rk)) 5 4 0 0 2 1 3 0 4 1
r0 r1 r2 r3 r4 r5 r6

Normalized h (P(rk)) 5/20 4/20


0 0
2/20 1/20 3/20 0 4/20 1/20

cdf F(rk) 5/20 9/20 11/20 12/20 15/20 19/20 20/20

sk =round(9•F(rk)) 2 4 5 5 7 9 9
s0 s1 s2 s3 s4 s5 s6

16
Histogram Equalization: Example

An 8x8 image

17
Histogram Equalization: Example
Fill in the following table/histogram

Image Histogram (Non-zero values)

18
Histogram Equalization: Example

Image Histogram (Non-zero values shown)

19
Histogram Equalization: Example

20
Histogram Equalization: Example

Cumulative Distribution Function (cdf)

Image Histogram/Prob Mass Function

21
Histogram Equalization: Example

Cumulative Distribution Function (cdf)

22
Histogram Equalization: Example

Cumulative Distribution Function (cdf)

23
Histogram Equalization: Example

Normalized Cumulative Distribution Function (cdf)

Divide each value by total number of


pixels (64) to get the normalized cdf

24
Histogram Equalization: Example
J  r , c   255  PI  I  r , c   .

If cdf is normalized

s  round (255.cdf (r ))
If cdf is NOT normalized
cdf (r )
s  round (255. )
M N
s  round (255.  46 / 64 )
s  183

183

Original Image

25
Histogram Equalization: Example

26
Histogram Equalization: Example

Original Image Corresponding histogram (red) and cumulative


histogram (black)

Image after histogram equalization Corresponding histogram (red) and cumulative


histogram (black)
27
Histogram Equalization: Example
Equalized Histogram
Dark image
Bright image

Equalized Histogram
28
Histogram Equalization: Example
Equalized Histogram
Low contrast
High Contrast

Equalized Histogram
29
HISTOGRAM MATCHING
(SPECIFICATION)
• HISTOGRAM EQUALIZATION DOES NOT ALLOW
INTERACTIVE IMAGE ENHANCEMENT AND
GENERATES ONLY ONE RESULT: AN
APPROXIMATION TO A UNIFORM HISTOGRAM.
• SOMETIMES THOUGH, WE NEED TO BE ABLE TO
SPECIFY PARTICULAR HISTOGRAM SHAPES
CAPABLE OF HIGHLIGHTING CERTAIN GRAY-LEVEL
RANGES.

30
HISTOGRAM SPECIFICATION
• THE PROCEDURE FOR HISTOGRAM-SPECIFICATION BASED
ENHANCEMENT IS:

– EQUALIZE THE LEVELS OF THE ORIGINAL IMAGE USING:

k nj
s  T (rk )  
j 0 n

n: total number of pixels,


nj: number of pixels with gray level rj,
L: number of discrete gray levels
31
HISTOGRAM SPECIFICATION

– SPECIFY THE DESIRED DENSITY FUNCTION AND OBTAIN THE


TRANSFORMATION FUNCTION G(z):

k
vk  G  z k    p z  z i   s k
i 0

pz: specified desirable PDF for output

32
HISTOGRAM SPECIFICATION

• THE NEW, PROCESSED VERSION OF THE


ORIGINAL IMAGE CONSISTS OF GRAY
LEVELS CHARACTERIZED BY THE SPECIFIED
DENSITY pz(z).
1 1
In essence: z  G ( s)  z  G [T (r )]

33
MAPPINGS

34
HISTOGRAM SPECIFICATION

• OBTAIN THE HISTOGRAM OF THE GIVEN IMAGE


• MAP EACH LEVEL rK TO A LEVEL SK
• OBTAIN THE TRANSFORMATION FUNCTION G FROM THE
GIVEN PZ (Z)
• PRECOMPUTE ZK FOR EACH VALUE OF SK
• FOR EACH PIXEL IN THE ORIGINAL IMAGE, IF THE VALUE
OF THAT PIXEL IS rk MAP THIS VALUE TO ITS
CORRESPONDING LEVEL SK, THEN MAP LEVEL SK INTO THE
FINAL VALUE ZK

35
HISTOGRAM SPECIFICATION
k nk pr(rk) sk pz(zk) vk nk
0 790 0.19 0.19 0 0 0
1 1023 0.25 0.44 0 0 0
2 850 0.21 0.65 0 0 0
3 656 0.16 0.81 0.15 0.15 790
4 329 0.08 0.89 0.2 0.35 1023
5 245 0.06 0.95 0.3 0.65 850
6 122 0.03 0.98 0.2 0.85 985
7 81 0.02 1.0 0.15 1.0 448

A 64X64 (4096 PIXELS) IMAGE WITH 8 GRAY LEVELS


36
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

37
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

38
39
GLOBAL/LOCAL HISTOGRAM EQUALIZATION
• IT MAY BE NECESSARY TO ENHANCE DETAILS OVER SMALL AREAS IN THE
IMAGE
• THE NUMBER OF PIXELS IN THESE AREAS MAY HAVE NEGLIGIBLE INFLUENCE
ON THE COMPUTATION OF A GLOBAL TRANSFORMATION WHOSE SHAPE
DOES NOT NECESSARILY GUARANTEE THE DESIRED LOCAL ENHANCEMENT
• DEVISE TRANSFORMATION FUNCTIONS BASED ON THE GRAY LEVEL
DISTRIBUTION IN THE NEIGHBORHOOD OF EVERY PIXEL IN THE IMAGE
• THE PROCEDURE IS:
– DEFINE A SQUARE (OR RECTANGULAR) NEIGHBORHOOD AND MOVE THE
CENTER OF THIS AREA FROM PIXEL TO PIXEL.
– AT EACH LOCATION, THE HISTOGRAM OF THE POINTS IN THE
NEIGHBORHOOD IS COMPUTED AND EITHER A HISTOGRAM
EQUALIZATION OR HISTOGRAM SPECIFICATION TRANSFORMATION
FUNCTION IS OBTAINED.
– THIS FUNCTION IS FINALLY USED TO MAP THE GRAY LEVEL OF THE PIXEL
CENTERED IN THE NEIGHBORHOOD.
– THE CENTER IS THEN MOVED TO AN ADJACENT PIXEL LOCATION AND THE
PROCEDURE IS REPEATED.

40
GLOBAL/LOCAL HISTOGRAM EQUALIZATION

41
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Global)
• LET r REPRESENT A GRAY LEVEL IN THE IMAGE [0, L-1], AND LET p(ri )
DENOTE THE NORMALIZED HISTOGRAM COMPONENT
CORRESPONDING TO THE ith VALUE OF r.
• THE nth MOMENT OF r ABOUT ITS MEAN IS DEFINED AS

L 1 n

 n r    ri  m  pri 
i 0
• WHERE m IS THE MEAN VALUE OF r (AVERAGE GRAY LEVEL)

m  i 0 ri pri 
L 1

42
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Global)
• THE SECOND MOMENT IS GIVEN BY

L 1 2

 2 r    ri  m  pri 
i 0

• WHICH IS THE VARIANCE OF r


• MEAN AS A MEASURE OF AVERAGE GRAY LEVEL IN THE IMAGE
• VARIANCE AS A MEASURE OF AVERAGE CONTRAST

43
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Local)
• LET (x,y) BE THE COORDINATES OF A PIXEL IN AN
IMAGE, AND LET SX,Y DENOTE A NEIGBORHOOD OF
SPECIFIED SIZE, CENTERED AT (x,y)
• THE MEAN VALUE mSXY OF THE PIXELS IN SX,Y IS

ms xy   r s ,t p rs ,t 
 s ,t
 S xy
• THE GRAY LEVEL VARIANCE OF THE PIXELS IN
REGION SX,Y IS GIVEN BY

S xy
2
  r s ,t 
 ms xy prs ,t 
2

 
s ,t S xy
44
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT
• THE GLOBAL MEAN AND VARIANCE ARE MEASURED
OVER AN ENTIRE IMAGE AND ARE USEFUL FOR
GROSS ADJUSTMENTS OF OVERALL INTENSITY AND
CONTRAST.
• A USE OF THESE MEASURES IN LOCAL
ENHANCEMENT IS, WHERE THE LOCAL MEAN AND
VARIANCE ARE USED AS THE BASIS FOR MAKING
CHANGES THAT DEPEND ON IMAGE
CHARACTERISTICS IN A PREDEFINED REGION ABOUT
EACH PIXEL IN THE IMAGE.

45
TUNGSTEN FILAMENT IMAGE

46
USE OF HISTOGRAM STATISTICS FOR IMAGE ENHANCEMENT

• A PIXEL AT POINT (x,y) IS CONSIDERED IF:


– mSXY ≤ k0MG, where k0 is a positive constant less than 1.0, and MG is
global mean
– σsxy ≤ k2DG, where DG is the global standard deviation and k2 is a
positive constant
– k1DG ≤ σsxy ,, with k1 < k2
• A PIXEL THAT MEETS ALL ABOVE CONDITIONS IS
PROCESSED SIMPLY BY MULTIPLYING IT BY A SPECIFIED
CONSTANT, E, TO INCREASE OR DECREASE THE VALUE OF
ITS GRAY LEVEL RELATIVE TO THE REST OF THE IMAGE.
• THE VALUES OF PIXELS THAT DO NOT MEET THE
ENHANCEMENT CONDITIONS ARE LEFT UNCHANGED.

47
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

48
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

49
Readings from Book (3rd Edn.)
• 3.3 Histogram
Acknowledgements
 Statistical Pattern Recognition: A Review – A.K Jain et al., PAMI (22) 2000
 Pattern Recognition and Analysis Course – A.K. Jain, MSU
Material in these slides has been taken from, the following resources

 Pattern Classification” by Duda et al., John Wiley & Sons.


 Digital Image Processing”, Rafael C. Gonzalez & Richard E. Woods, Addison-Wesley, 2002
 Machine Vision: Automated Visual Inspection and Robot Vision”, David Vernon, Prentice Hall,
1991
 www.eu.aibo.com/
 Advances in Human Computer Interaction, Shane Pinder, InTech, Austria, October 2008

51

You might also like