You are on page 1of 55

Digital Image Processing

Lecture # 5
Spatial Enhancement-II

1
Image Enhancement

2
Histogram of a Grayscale Image

lower RHC: number of pixels with intensity g

black marks pixels with intensity g


16-level (4-bit) image

3
Histogram of a Grayscale Image

Black marks
pixels with
intensity g

Plot of histogram:
number of pixels with intensity g

4
Histogram of a Grayscale Image

Black marks
pixels with
intensity g

Plot of histogram:
number of pixels with intensity g

5
Histogram of a Grayscale Image

hhI  gg   the


thenumber
number
I
of
ofpixels
pixelsininII
with
withgraylevel
graylevelgg. .

6
Histogram of a Color Image

 IfIfIIisisaa3-band
3-bandimageimage
 then
thenI(r,c,b)
I(r,c,b) isisan
aninteger
integer between
between00and
and255.
255.
 II has
has33histograms:
histograms:
 hhR(g) = # of pixels in I(:,:,1) with intensity value g
R(g) = # of pixels in I(:,:,1) with intensity value g


 hhG(g)
(g)==##of
ofpixels
pixelsininI(:,:,2)
I(:,:,2) with
withintensity
intensityvalue
valuegg
G
 hhB(g) = # of pixels in I(:,:,3) with intensity value g
B(g) = # of pixels in I(:,:,3) with intensity value g

7
Histogram of a Color Image

There
Thereisisone
onehisto-
histo-
gram
gramper
percolor
colorband
band
R,
R,G,
G,&&B.
B.Luminosity
Luminosity
histogram
histogramisisfrom
from11
band
band==(R+G+B)/3
(R+G+B)/3

8
Histogram: Example

Dark Image

How would the


histograms of these
images look like?

Bright Image

9
Histogram: Example
Dark image
Components of
histogram are
concentrated on
the low side of
the gray scale

Bright image
Components of
histogram are
concentrated on
the high side of
the gray scale
10
HISTOGRAM INSIGHT INTO CONTRAST

11
Histogram: Example

Low Contrast Image

How would the


histograms of these
images look like?

High Contrast Image

12
Histogram: Example

Low contrast image


Histogram is narrow and
centered toward the
middle of the gray scale

High contrast image


Histogram covers broad
range of the gray scale
and the distribution of
pixels is not too far from
uniform with very few
vertical lines being much
higher than the others
13
Contrast Stretching

Improve the contrast in an


image by `stretching' the
range of intensity values it
contains to span a desired
range of values, e.g. the
the full range of pixel
values

14
Contrast Stretching

If rmax and rmin are the maximum and minimum gray


level of the input image and L is the total gray
levels of output image, the transformation function
for contrast stretch will be
L

255
 L 1 
s  T (r )  (r  rmin )  
r  r

127
 max min 

0
0 rmin 127 rmax255

15
Contrast Stretching

16
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

17
HISTOGRAM EQUALIZATION

18
AERIAL PHOTOGRAPH OF THE PENTAGON

Resulting image uses more of dynamic range.


19
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
This is the
the probability
probability
1 that an
that an arbitrary
arbitrary pixel
pixel
pI  g   hI  g 
A from II has
from has value
value g.
g.

20
The Probability Distribution Function
of an Image

•• p(g)
p(g)isisthe
thefraction
fractionof
of pixels
pixelsin
inan
animage
imagethat
thathave
have
intensity
intensityvalue
value g.
g.
•• p(g)
p(g)isisthe
theprobability
probabilitythat
thataapixel
pixelrandomly
randomlyselected
selected
from
fromthethegiven
givenimage
imagehashasintensity
intensityvalue
value g.
g.
•• Whereas
Whereasthe thesum
sumofofthe
thehistogram
histogram h(g)
h(g)over
overall
all gg from
from
00to
to 255
255isis equal
equaltotothe
thenumber
numberof ofpixels
pixelsininthe
theimage,
image,
the
thesum
sumofof p(g)
p(g)over
overall
all gg isis 1.
1.
•• ppisisthe
the normalized
normalizedhistogram
histogram of
ofthe
theimage
image

21
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
,
A  0
 0


0
h  
I

where hI(γ ) is the


histogram of
This is
This is the
the probability
probability that
that
image I. any given
any given pixel
pixel from
from II has
has
value less
value less than
than or
or equal
equal to
to g.
g.

22
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 Alsocalled
Also calledCDF
CDF
level. The probability that q ≤ g is given by for“Cumulative
for “Cumulative
Distribution
Distribution
g
Function”.
Function”.
g
1 g
 h  
I

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


0
h  
I

where hI(γ ) is the


histogram of
This is
This is the
the probability
probability that
that
image I. any given
any given pixel
pixel from
from II has
has
value less
value less than
than or
or equal
equal to
to g.
g.

23
The Cumulative Distribution Function
of an Image
•• P(g)
P(g) isisthe
thefraction
fractionof
ofpixels
pixelsininananimage
imagethat
that have
haveintensity
intensity
values
values less
less than
thanor
orequal
equaltoto g.
g.
•• P(g)
P(g) isisthe
theprobability
probabilitythat
thataapixel
pixelrandomly
randomlyselected
selectedfrom
from
the
the given
givenbandbandhas
hasananintensity
intensityvalue
valueless
lessthan
thanor
or equal
equalto
to
g.
g.
•• P(g)
P(g) isisthe
thecumulative
cumulative(or
(orrunning)
running) sum
sum of
of p(g)
p(g) from
from00
through
through gginclusive.
inclusive.
•• P(0)
P(0) == p(0)
p(0) and
and P(255)
P(255)== 1;
1;

24
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.

25
Histogram Equalization
TheCDF
The CDF(cumulative
(cumulative
distribution)isisthe
distribution) the
pdf
LUTfor
LUT forremapping.
remapping.

CDF

26
Histogram Equalization
TheCDF
The CDF(cumulative
(cumulative
distribution)isisthe
distribution) the
pdf
LUTfor
LUT forremapping.
remapping.

LUT

27
Histogram Equalization
TheCDF
The CDF(cumulative
(cumulative
distribution)isisthe
distribution) the
pdf
LUTfor
LUT forremapping.
remapping.

LUT

28
Histogram Equalization

29
Histogram Equalization
Luminosity

before

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

30
HISTOGRAM EQUALIZATION
IMPLEMENTATION

0 0 0 0 0
1 1 1 1 4
4 5 6 6 6
8 8 8 8 9

31
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

32
Histogram Equalization: Example

Original Image Corresponding histogram (red) and cumulative


histogram (black)

Image after histogram equalization Corresponding histogram (red) and cumulative


histogram (black)
33
Histogram Equalization: Example
Equalized
EqualizedHistogram
Histogram
image
Darkimage
Dark image
Brightimage
Bright

Equalized
EqualizedHistogram
Histogram
34
Histogram Equalization: Example
Equalized
EqualizedHistogram
Histogram
contrast
Lowcontrast
Low Contrast
HighContrast
High

Equalized
EqualizedHistogram
Histogram
35
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.

36
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
37
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

38
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 )]

39
MAPPINGS

40
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

41
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


42
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.

43
GLOBAL/LOCAL HISTOGRAM EQUALIZATION

45
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

46
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

47
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

 r 
 ms xy p rs ,t 
2 2
 S xy  s ,t
 s ,t S xy
48
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.

49
TUNGSTEN FILAMENT IMAGE

50
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.

51
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

52
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

53
Readings from Book (3 Edn.)
rd

• 3.3 Histogram
Acknowledgements
 Statistical Pattern Recognition: A Review – A.K Jain et al., PAMI (22) 2000

Material in these slides has been taken from, the following resources

Pattern Recognition and Analysis Course – A.K. Jain, MSU


 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

55

You might also like