0% found this document useful (0 votes)
11 views46 pages

DIP03-Image Enhancement-Historgram Equalization

This lecture covers image enhancement techniques focusing on histogram equalization and matching. It explains the concept of histograms in digital images, how to perform histogram equalization to enhance image contrast, and the process of histogram matching to achieve a desired output histogram. The lecture concludes with examples and discusses the limitations of histogram equalization.

Uploaded by

Vu Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views46 pages

DIP03-Image Enhancement-Historgram Equalization

This lecture covers image enhancement techniques focusing on histogram equalization and matching. It explains the concept of histograms in digital images, how to perform histogram equalization to enhance image contrast, and the process of histogram matching to achieve a desired output histogram. The lecture concludes with examples and discusses the limitations of histogram equalization.

Uploaded by

Vu Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Lecture 03

Image Enhancement
Histogram Equalization
Contents

In this lecture we will look at image enhancement point


processing techniques:
 What is histogram?
 Histogram equalization
 Histogram matching

Image Enhancement-Histogram Equalization 2


What is the histogram of a digital image?

 The histogram of a digital image with gray values


r0 , r1 ,, rL1 is the discrete function

nk
p(rk ) 
n
nk: Number of pixels with gray value rk
n: total Number of pixels in the image

 The function p(rk) represents the fraction of the total


number of pixels with gray value rk.

Image Enhancement-Histogram Equalization 3


What is the histogram of a digital image?

 Histogram provides a global description of the


appearance of the image.

 If we consider the gray values in the image as


realizations of a random variable R, with some
probability density, histogram provides an
approximation to this probability density. In other
words,

Pr( R  rk )  p(rk )

Image Enhancement-Histogram Equalization 4


Some typical histograms

 The shape of a histogram provides useful information


for contrast enhancement

Dark image

Image Enhancement-Histogram Equalization 5


Some typical histograms

Bright image

Low contrast
image

Image Enhancement-Histogram Equalization 6


Some typical histograms

High contrast image

Image Enhancement-Histogram Equalization 7


Histogram equalization

 The histogram equalization is an approach to enhance


a given image. The approach is to design a
transformation T(.) such that the gray values in the
output is uniformly distributed in [0, 1].

 Let us assume for the moment that the input image to


be enhanced has continuous gray values, with r = 0
representing black and r = 1 representing white.

 We need to design a gray value transformation s =


T(r), based on the histogram of the input image, which
will enhance the image.

Image Enhancement-Histogram Equalization 8


Histogram equalization

we assume that:
 T(r) is a monotonically
increasing function for
0 r 1 (preserves
order from black to
white).
 T(r) maps [0,1] into
[0,1] (preserves the
range of allowed Gray
values).

Image Enhancement-Histogram Equalization 9


Histogram equalization

 Let us denote the inverse transformation by r T -1(s) .


We assume that the inverse transformation also
satisfies the above two conditions.

 We consider the gray values in the input image and


output image as random variables in the interval [0, 1].

 Let pin(r) and pout(s) denote the probability density of


the Gray values in the input and output images.

Image Enhancement-Histogram Equalization 10


Histogram equalization

 If pin(r) and T(r) are known, and r T -1(s) satisfies


condition 1, we can write (result from probability
theory): dr  
pout ( s)   pin (r ) 
 ds  r T 1 ( s )
 One way to enhance the image is to design a
transformation T(.) such that the gray values in the
output is uniformly distributed in [0, 1], i.e. pout (s)  1,
0  s 1
 In terms of histograms, the output image will have all
gray values in “equal proportion” .
 This technique is called histogram equalization.

Image Enhancement-Histogram Equalization 11


Histogram equalization

 Next we derive the gray values in the output is


uniformly distributed in [0, 1].
 Consider the transformation
r
s  T (r )   pin ( w)dw , 0  r 1
0

 Note that this is the cumulative distribution function


(CDF) of pin (r) and satisfies the previous two
conditions.
 From the previous equation and using the fundamental
theorem of calculus,
ds
 pin (r )
dr

Image Enhancement-Histogram Equalization 12


Histogram equalization

 Therefore, the output histogram is given by


 1 
pout ( s )   pin (r )    1r T 1 ( s )  1, 0  s 1
 pin (r )  r T 1 ( s )

 The output probability density function is uniform,


regardless of the input.
 Thus, using a transformation function equal to the CDF
of input gray values r, we can obtain an image with
uniform gray values.
 This usually results in an enhanced image, with an
increase in the dynamic range of pixel values.

Image Enhancement-Histogram Equalization 13


How to implement histogram equalization

 Step 1:For images with discrete gray values, compute:


nk
pin (rk )  0  rk  1 0  k  L 1
n
L: Total number of gray levels
nk: Number of pixels with gray value rk
n: Total number of pixels in the image
 Step 2: Based on CDF, compute the discrete version
of the previous transformation :
k
s k  T (rk )   pin (r j ) 0  k  L 1
j 0

Image Enhancement-Histogram Equalization 14


Example

 Consider an 8-level 64 x 64 image with gray values (0,


1, …, 7). The normalized gray values are (0, 1/7, 2/7,
…, 1). The normalized histogram is given below:

 NB: The gray values in output are also (0, 1/7, 2/7, …, 1).

Image Enhancement-Histogram Equalization 15


Example

# pixels Fraction
of # pixels

Gray value Normalized gray value

Image Enhancement-Histogram Equalization 16


Example
k
 Applying the transformation,s k  T (rk )   pin (r j ) we have
j 0

Image Enhancement-Histogram Equalization 17


Example

 Notice that there are only five distinct gray levels ---
(1/7, 3/7, 5/7, 6/7, 1) in the output image. We will
relabel them as (s0, s1, …, s4 ).
 With this transformation, the output image will have
histogram

Image Enhancement-Histogram Equalization 18


Example
Histogram of output image

# pixels

Gray values
 Note that the histogram of output image is only
approximately, and not exactly, uniform. This should not be
surprising, since there is no result that claims uniformity in
the discrete case.
Image Enhancement-Histogram Equalization 19
Example Original image and its histogram

Image Enhancement-Histogram Equalization 20


Example
Histogram equalized image and its histogram

Image Enhancement-Histogram Equalization 21


Example

Image Enhancement-Histogram Equalization 22


Example

Image Enhancement-Histogram Equalization 23


Example

Image Enhancement-Histogram Equalization 24


Comments

 Histogram equalization may not always produce


desirable results, particularly if the given histogram is
very narrow. It can produce false edges and regions. It
can also increase image “graininess” and “patchiness.”

Image Enhancement-Histogram Equalization 25


Comments

Image Enhancement-Histogram Equalization 26


Histogram matching
 Histogram equalization yields an image whose pixels
are (in theory) uniformly distributed among all gray
levels.
 Sometimes, this may not be desirable. Instead, we
may want a transformation that yields an output image
with a pre-specified histogram. This technique is called
histogram specification.
z=H(r)

Input Uniform Output


image s=T(r) image v=G(z) image

Image Enhancement-Histogram Equalization 27


Histogram matching
 Suppose, the input image has probability density in p(r). We
want to find a transformation z H (r) , such that the
probability density of the new image obtained by this
transformation is pout(z) , which is not necessarily uniform.
 First apply the transformation
r
s  T (r )   pin ( w)dw , 0  r 1 (*)
0
This gives an image with a uniform probability density.
 If the desired output image were available, then the
following transformation would generate an image with
uniform density:
z
v  G ( z )   pout ( w)dw, 0  z 1 (**)
0
Image Enhancement-Histogram Equalization 28
Histogram matching
 From the gray values nwe can obtain the gray values
z by using the inverse transformation, z  G-1(v)

 If instead of using the gray values nobtained from (**),


we use the gray values s obtained from (*) above (both
are uniformly distributed ! ), then the point
transformation
z=H(r)= G-1[ v=s =T(r)]

will generate an image with the specified density out


p(z), from an input image with density in p(r) !

Image Enhancement-Histogram Equalization 29


Histogram matching
 For discrete gray levels, we have
k
s k  T (rk )   pin (r j ) 0  k  L 1
j 0
k
vk  G ( z k )   pout ( z j )  sk 0  k  L 1
j 0

 If the transformation zk G(zk) is one-to-one, the


inverse transformation sk G-1 (sk) , can be easily
determined, since we are dealing with a small set of
discrete gray values.
 In practice, this is not usually the case (i.e., ) zk 
G(zk) is not one-to-one) and we assign gray values to
match the given histogram, as closely as possible.
Image Enhancement-Histogram Equalization 30
Algorithm for histogram matching

 Step 1: Equalize input image to get an image with


uniform gray values, using the discrete equation:
k
s k  T (rk )   pin (r j ) 0  k  L 1
j 0

 Step 2: Based on desired histogram to get an image


with uniform gray values, using the discrete equation:
k
vk  G ( z k )   pout ( z j )  sk 0  k  L 1
j 0

 Step 3:
1 1
  
z G ( v=s ) z G [T ( r )]

Image Enhancement-Histogram Equalization 31


Example

 Consider an 8-level 64 x 64 previous image.

# pixels

Gray value

Image Enhancement-Histogram Equalization 32


Example

 It is desired to transform this image into a new image,


using a transformation Z=H(r)= G-1[T(r)], with
histogram as specified below:

# pixels

Gray values

Image Enhancement-Histogram Equalization 33


Example

 Step 1: The transformation T(r) was obtained earlier


(reproduced below):

Image Enhancement-Histogram Equalization 34


Example

 Step 2: we compute the transformation G as before.

Image Enhancement-Histogram Equalization 35


Example

 Step 3: Computer z=G-1 (s=v),Notice that G is not


invertible.
G-1(0) = ?
G-1(1/7) = 3/7
G-1(2/7) = 4/7
G-1(3/7) = ?
G-1(4/7) = ?
G-1(5/7) = 5/7
G-1(6/7) = 6/7
G-1(1) = 1

Image Enhancement-Histogram Equalization 36


Example

 Combining the two transformation T and G-1 , compute


z=H(r)= G-1[v=s=T(r)]

Image Enhancement-Histogram Equalization 37


Example

 Applying the transformation H to the original image


yields an image with histogram as below:

 Again, the actual histogram of the output image does


not exactly but only approximately matches with the
specified histogram. This is because we are dealing
with discrete histograms.
Image Enhancement-Histogram Equalization 38
Example

Original image and its histogram

Histogram specified image and its histogram


Image Enhancement-Histogram Equalization 39
Example

Desired histogram

Image Enhancement-Histogram Equalization 40


Example

Image Enhancement-Histogram Equalization 41


Example

Image Enhancement-Histogram Equalization 42


Example

Image Enhancement-Histogram Equalization 43


Example

Image Enhancement-Histogram Equalization 44


Example

Image Enhancement-Histogram Equalization 45


Summary

 We have looked at histogram equalization and


histogram matching

 Next time we will start to look at neighbourhood


operations – in particular filtering and convolution

Image Enhancement-Histogram Equalization 46

You might also like