You are on page 1of 24

Digital Image Processing

Lecture 6
Histogram and Histogram
Equalization
Spring 2016

Histograms
Histogram of an image with gray level (0 to L-1):
A discrete function h(rk) = nk , where rk is the kth gray level and nk is
the number of pixels in the image having gray level rk .
How a histogram is obtained?
For B-bit image, initialize 2B counters with 0
Loop over all pixels x,y
When encountering gray level f(x,y)=i, increment counter # i
Normalized histogram:
A discrete function p(rk) = nk/n , where n is the total number of
pixels in the image. p(rk) estimates probability of occurrence of
gray-level rk
2/23/2016

CIIT, Islamabad

Digital Image Processing

Histogram: application
Distribution of gray-levels can be judged by measuring a histogram

Histogram provides global descriptions of the image (no local


details)

2/23/2016

CIIT, Islamabad

Digital Image Processing

Example Histogram

2/23/2016

CIIT, Islamabad

Digital Image Processing

Example Histogram

2/23/2016

CIIT, Islamabad

Digital Image Processing

Histogram Examples

2/23/2016

CIIT, Islamabad

Digital Image Processing

Histogram equalization
The idea of histogram equalization is that the pixels should
be distributed evenly over the whole intensity range, i.e. the
aim is to transform the image so that the output image has a
flat histogram.

Histogram equalization employs a monotonic, non-linear mapping which re-assigns


the intensity values of pixels in the input image such that the output image contains a
uniform distribution of intensities (i.e. a flat histogram).
Histogram equalization involves finding a grey scale transformation function
with a uniformDigital
histogram
(or nearly so).
2/23/2016 that creates an output image
CIIT, Islamabad
Image Processing

How do we determine this grey scale transformation function?


Assume our grey levels are continuous and have been normalized to
lie between 0 (black) and 1 (white).

We must find a transformation T that maps grey values r in the input image
F to grey values s = T(r) in the transformed image .
It is assumed that

T is single valued and monotonically increasing, and


for

The inverse transformation from s to r is given by :

r = T-1(s).
2/23/2016

CIIT, Islamabad

Digital Image Processing

Histogram equalization: continuous case


Idea: To find a non-linear transformation

s = T (r)
to be applied to each pixel of the input image f(x,y), such that a
uniform distribution of gray levels in the entire range results for
the output image g(x,y).

Assuming ideal, continuous case, with normalized histograms


that

0 r 1 and 0 s 1
T(r) is single valued i.e., there exists r= T-1(r)

T(r) is monotonically increasing


2/23/2016

CIIT, Islamabad

Digital Image Processing

Single valued monotonically increasing function


A function T(r) is monotonically increasing
if T(r1) < T(r2) for r1 < r2,
and monotonically decreasing
if T(r1) > T(r2) for r1 < r2.

Example of a transformation function


which is both single valued and
monotonically increasing
2/23/2016

CIIT, Islamabad

Digital Image Processing

10

Background (probability distribution)


Assume continuous random variables
The cumulative probability distribution function or cumulative
distribution function (cdf)
The probability that the random variable is less than or equal to a
specified constant a. We write this as

for all values of a (i.e., < a < ),


The probability density function (pdf) or density function of random
variable x is defined as the derivative of the cdf:

2/23/2016

CIIT, Islamabad

Digital Image Processing

11

Histogram equalization: Discrete case


The discrete approximation of the transformation function for histogram
equalization is:
k

sk T (rk ) pr (rj ) for 0 k L 1


j 0

where

pr ( r j )

nj
n

L 1

j 0,........, L 1 and n n j
j 0

nj : number of pixels with gray level rj


n : total number of pixels
Note: For digital images, gray-level pdf cannot be
exactly uniform after histogram equalization

2/23/2016

CIIT, Islamabad

Digital Image Processing

12

Histogram equalization examples


Input image

Input histogram and cdf


2/23/2016

CIIT, Islamabad

Output image

Output histogram and cdf


Digital Image Processing

13

Histogram equalization examples


Low contrast image

Output image
Equalized histogram

Equalized histogram
high contrast image
2/23/2016

Output image
CIIT, Islamabad

Digital Image Processing

14

Histogram equalization examples


Dark input image

Output image
Equalized histogram

Equalized histogram
Bright input image
2/23/2016

Output image
CIIT, Islamabad

Digital Image Processing

15

Histogram equalization examples

Transformation functions for


histogram equalization
2/23/2016

CIIT, Islamabad

Digital Image Processing

16

Histogram equalization examples

2/23/2016

CIIT, Islamabad

Digital Image Processing

17

Histogram equalization examples

2/23/2016

CIIT, Islamabad

Digital Image Processing

18

Histogram equalization examples

2/23/2016

CIIT, Islamabad

Digital Image Processing

19

Histogram equalization examples

2/23/2016

CIIT, Islamabad

Digital Image Processing

20

Local Histogram enhancement


1. Histogram equalization techniques are based on graylevel distribution over the entire image
2. gray-levels containing important information in a small
neighborhood (region of interest) may not be present in
sufficient quantities to affect the computation of a
mapping based on global information
3. at each pixel do the following
- compute the cumulative histogram based on a small
neighborhood around the pixel to be mapped
- apply histogram equalization using this cumulative
histogram
2/23/2016

CIIT, Islamabad

Digital Image Processing

21

Local enhancement
Histogram using a local neighborhood, for example
7*7 neighborhood

2/23/2016

CIIT, Islamabad

Digital Image Processing

22

Histogram using a local 3*3 neighborhood

2/23/2016

CIIT, Islamabad

Digital Image Processing

23

Color processing
1.can apply histogram equalization to color images
2. don't want to apply it using the RGB color model
- equalizing R, G, and B bands independently
causes color shifts
3. must convert to a color model that separates
intensity information from color information (e.g.
HSI)

4. can then apply histogram equalization on the


intensity band

2/23/2016

CIIT, Islamabad

Digital Image Processing

24

You might also like