Thi Giac May Tinh Vo Quang Hoang Khang Dip03 Image Enhancement Historgram Equalization (Cuuduongthancong - Com)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

Lecture 03

om
.c
Image Enhancement

ng
co
Histogram Equalization

an
th
o ng
du
u
cu

CuuDuongThanCong.com https://fb.com/tailieudientucntt
Contents

In this lecture we will look at image enhancement point

om
processing techniques:

.c
 What is histogram?

ng
 Histogram equalization

co
 Histogram matching

an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 2


CuuDuongThanCong.com https://fb.com/tailieudientucntt
What is the histogram of a digital image?

 The histogram of a digital image with gray values

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

.c
ng
nk
p(rk ) 

co
n

an
nk: Number of pixels with gray value rk
th
ng
n: total Number of pixels in the image
o
du
u

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


cu

number of pixels with gray value rk.

Image Enhancement-Histogram Equalization 3


CuuDuongThanCong.com https://fb.com/tailieudientucntt
What is the histogram of a digital image?

 Histogram provides a global description of the

om
appearance of the image.

.c
ng
 If we consider the gray values in the image as

co
realizations of a random variable R, with some

an
probability density, histogram provides an

th
approximation to this probability density. In other
ng
words,
o
du

Pr( R  rk )  p(rk )
u
cu

Image Enhancement-Histogram Equalization 4


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Some typical histograms

 The shape of a histogram provides useful information

om
for contrast enhancement

.c
ng
co
an
th
ng
Dark image
o
du
u
cu

Image Enhancement-Histogram Equalization 5


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Some typical histograms

om
Bright image

.c
ng
co
an
th
o ng
du

Low contrast
u

image
cu

Image Enhancement-Histogram Equalization 6


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Some typical histograms

om
.c
ng
High contrast image

co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 7


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram equalization

 The histogram equalization is an approach to enhance

om
a given image. The approach is to design a

.c
transformation T(.) such that the gray values in the
output is uniformly distributed in [0, 1].

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

an
be enhanced has continuous gray values, with r = 0
th
ng
representing black and r = 1 representing white.
o
du

 We need to design a gray value transformation s =


u
cu

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


will enhance the image.

Image Enhancement-Histogram Equalization 8


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram equalization

we assume that:

om
 T(r) is a monotonically

.c
increasing function for
0 r 1 (preserves

ng
co
order from black to

an
white).

th
 T(r) maps [0,1] into ng
[0,1] (preserves the
o
du

range of allowed Gray


u

values).
cu

Image Enhancement-Histogram Equalization 9


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram equalization

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

om
We assume that the inverse transformation also

.c
satisfies the above two conditions.

ng
 We consider the gray values in the input image and

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

an
th
ng
 Let pin(r) and pout(s) denote the probability density of
o
the Gray values in the input and output images.
du
u
cu

Image Enhancement-Histogram Equalization 10


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram equalization

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

om
condition 1, we can write (result from probability

.c
theory): dr  
pout ( s)   pin (r ) 

ng
 ds  r T 1 ( s )

co
 One way to enhance the image is to design a

an
transformation T(.) such that the gray values in the
th
output is uniformly distributed in [0, 1], i.e. pout (s)  1,
ng
0  s 1
o
du

 In terms of histograms, the output image will have all


u
cu

gray values in “equal proportion” .


 This technique is called histogram equalization.

Image Enhancement-Histogram Equalization 11


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram equalization

 Next we derive the gray values in the output is

om
uniformly distributed in [0, 1].
 Consider the transformation

.c
r
s  T (r )   pin ( w)dw ,

ng
0  r 1

co
0

 Note that this is the cumulative distribution function

an
(CDF) of pin (r) and satisfies the previous two
th
ng
conditions.
o
 From the previous equation and using the fundamental
du

theorem of calculus,
u
cu

ds
 pin (r )
dr

Image Enhancement-Histogram Equalization 12


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram equalization

 Therefore, the output histogram is given by

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

.c

 pin (r )  r T 1 ( s )

ng
co
 The output probability density function is uniform,

an
regardless of the input.
th
 Thus, using a transformation function equal to the CDF
ng
of input gray values r, we can obtain an image with
o
du

uniform gray values.


u

 This usually results in an enhanced image, with an


cu

increase in the dynamic range of pixel values.

Image Enhancement-Histogram Equalization 13


CuuDuongThanCong.com https://fb.com/tailieudientucntt
How to implement histogram equalization

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

om
nk
pin (rk )  0  rk  1 0  k  L 1

.c
n

ng
L: Total number of gray levels

co
an
nk: Number of pixels with gray value rk

th
n: Total number of pixels in the image
ng
 Step 2: Based on CDF, compute the discrete version
o
du

of the previous transformation :


u
cu

k
s k  T (rk )   pin (r j ) 0  k  L 1
j 0

Image Enhancement-Histogram Equalization 14


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

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

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

.c
ng
co
an
th
o ng
du
u
cu

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

Image Enhancement-Histogram Equalization 15


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
# pixels

ng
Fraction

co
of # pixels

an
th
o ng
du

Gray value Normalized gray value


u
cu

Image Enhancement-Histogram Equalization 16


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example
k
 Applying the transformation,s k  T (rk )   pin (r j ) we have
j 0

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 17


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

 Notice that there are only five distinct gray levels ---

om
(1/7, 3/7, 5/7, 6/7, 1) in the output image. We will
relabel them as (s0, s1, …, s4 ).

.c
 With this transformation, the output image will have

ng
co
histogram

an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 18


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example
Histogram of output image

om
.c
# pixels

ng
co
an
th
o ng
du

Gray values
u

 Note that the histogram of output image is only


cu

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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example Original image and its histogram

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 20


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example
Histogram equalized image and its histogram

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 21


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 22


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 23


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 24


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Comments

 Histogram equalization may not always produce

om
desirable results, particularly if the given histogram is

.c
very narrow. It can produce false edges and regions. It
can also increase image “graininess” and “patchiness.”

ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 25


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Comments

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 26


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram matching
 Histogram equalization yields an image whose pixels

om
are (in theory) uniformly distributed among all gray

.c
levels.
 Sometimes, this may not be desirable. Instead, we

ng
co
may want a transformation that yields an output image

an
with a pre-specified histogram. This technique is called

th
histogram specification. ng
o
z=H(r)
du
u
cu

Input Uniform Output


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

Image Enhancement-Histogram Equalization 27


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram matching
 Suppose, the input image has probability density in p(r). We
want to find a transformation z H (r) , such that the

om
probability density of the new image obtained by this

.c
transformation is pout(z) , which is not necessarily uniform.

ng
 First apply the transformation

co
r

an
s  T (r )   pin ( w)dw , 0  r 1 (*)

th
0
ng
This gives an image with a uniform probability density.
o

 If the desired output image were available, then the


du

following transformation would generate an image with


u
cu

uniform density:
z
v  G ( z )   pout ( w)dw, 0  z 1 (**)
0
Image Enhancement-Histogram Equalization 28
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram matching
 From the gray values nwe can obtain the gray values
z by using the inverse transformation, z  G-1(v)

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

co
we use the gray values s obtained from (*) above (both

an
are uniformly distributed ! ), then the point

th
transformation ng
o
z=H(r)= G-1[ v=s =T(r)]
du
u
cu

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


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Histogram matching
 For discrete gray levels, we have

om
k
s k  T (rk )   pin (r j ) 0  k  L 1

.c
j 0

ng
k
vk  G ( z k )   pout ( z j )  sk 0  k  L 1

co
j 0

an
 If the transformation zk G(zk) is one-to-one, the
th
inverse transformation sk G-1 (sk) , can be easily
o ng
determined, since we are dealing with a small set of
du

discrete gray values.


u
cu

 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
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Algorithm for histogram matching

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

om
uniform gray values, using the discrete equation:

.c
k
s k  T (rk )   pin (r j ) 0  k  L 1

ng
j 0

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

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

 Step 3:
u
cu

1 1
  
z G ( v=s ) z G [T ( r )]

Image Enhancement-Histogram Equalization 31


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

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

om
.c
ng
co
# pixels

an
th
o ng
du
u
cu

Gray value

Image Enhancement-Histogram Equalization 32


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

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

om
using a transformation Z=H(r)= G-1[T(r)], with

.c
histogram as specified below:

ng
co
an
th
# pixels
ng
o
du
u
cu

Gray values

Image Enhancement-Histogram Equalization 33


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

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

om
(reproduced below):

.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 34


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

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

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 35


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

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

om
invertible.

.c
G-1(0) = ?

ng
G-1(1/7) = 3/7

co
G-1(2/7) = 4/7

an
G-1(3/7) = ?
th
ng
G-1(4/7) = ?
o
G-1(5/7) = 5/7
du

G-1(6/7) = 6/7
u
cu

G-1(1) = 1

Image Enhancement-Histogram Equalization 36


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

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

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

.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 37


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

 Applying the transformation H to the original image

om
yields an image with histogram as below:

.c
ng
co
an
th
o ng
du

 Again, the actual histogram of the output image does


u
cu

not exactly but only approximately matches with the


specified histogram. This is because we are dealing
with discrete histograms.
Image Enhancement-Histogram Equalization 38
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
Original image and its histogram

th
o ng
du
u
cu

Histogram specified image and its histogram


Image Enhancement-Histogram Equalization 39
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
Desired histogram

ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 40


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 41


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 42


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 43


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 44


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Example

om
.c
ng
co
an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 45


CuuDuongThanCong.com https://fb.com/tailieudientucntt
Summary

 We have looked at histogram equalization and

om
histogram matching

.c
ng
 Next time we will start to look at neighbourhood

co
operations – in particular filtering and convolution

an
th
o ng
du
u
cu

Image Enhancement-Histogram Equalization 46


CuuDuongThanCong.com https://fb.com/tailieudientucntt

You might also like