You are on page 1of 76

raj@pilani.bits-pilani.ac.

in

L-6

Brief introduction to probability theory

Random: that cannot be predicted

random event, random function, random variable

Random experiment : it is not possible to


predict accurately the outcome
e.g., tossing of a coin, or dice
raj@pilani.bits-pilani.ac.in

nH  nT  n
where

nH  number of heads
nT  number of tails
n  total number of tossing

nH nT
  1
n n
raj@pilani.bits-pilani.ac.in

Important property: 0  P ( A)  1

Cumulative Probability distribution function:

F (a )  P ( x  a )

F(a) is the CDF of the random variable x


having the value less than or equal to a
raj@pilani.bits-pilani.ac.in

Properties of CDF:

1. F ( )  0
2. F (  )  1
3. 0  F ( x )  1
4. F ( x1 )  F ( x 2 ) if x1  x 2
5. P ( x1  x  x 2 )  F ( x 2 )  F ( x1 )
6. F ( x )  F ( x ) if x  x   ,   0
 
raj@pilani.bits-pilani.ac.in
Probability Density function (PDF) :
is defined as derivative of CDF
dF ( x )
p( x ) 
dx
Properties: 1. p( x )  0 for all x

2.  p( x )dx  1

x
3. F ( x )   p( )d

x2

4. P ( x1  x  x 2 )   p( x )dx
x1
raj@pilani.bits-pilani.ac.in

Histogram Processing

The histogram of a digital image with gray levels

in the range [0,L-1] is a discrete function

h( rk )  nk

where rk = kth gray level


nk = number of pixels in the image
having gray level value rk
raj@pilani.bits-pilani.ac.in

Normalization:

h( rk ) nk
p( rk )  
n n

n = total number of pixels in the image

p( rk ) = probability of occurrence of gray level


rk

 p(r )  1
k
k
raj@pilani.bits-pilani.ac.in
p(rk) =h(rk)/n

rk = 255

 p(r )  1
k
k
raj@pilani.bits-pilani.ac.in

Uniformly distributed
histogram yields

HIGH CONTRAST IMAGE

Hence, histogram
processing requires the
stretching of gray level
uniformly over the entire
gray level range.

This is histogram equalization


raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

Histogram

p(r)

r =1
raj@pilani.bits-pilani.ac.in

Histogram equalization

p(s)

s
0 1
raj@pilani.bits-pilani.ac.in

1. Requires the distribution of histogram peaks


uniformly over the entire gray level range

2. Equalize the height of the peaks

Let us define the gray level values (r) to be

• Continuous and

• Normalized between [0,1]


raj@pilani.bits-pilani.ac.in

r0 Black

r 1 White

For any r, the transformation

s  T (r ) ; 0  r  1
raj@pilani.bits-pilani.ac.in

Let us require that the transformation


function T(r) should satisfy

1. T(r) is single valued and monotonically


increasing in the interval 0 ≤ r ≤ 1

2. 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1
raj@pilani.bits-pilani.ac.in

s
T(r)  Single valued
and
monotonically increasing
r
raj@pilani.bits-pilani.ac.in

s T(r)  Not single valued

Inverse transformation of the T(r) will not


give the original image
raj@pilani.bits-pilani.ac.in

Non-monotonic transformation function

T(r)
s

r
Transformation Transformation
from black  white from white  black
raj@pilani.bits-pilani.ac.in

Original negative 1st half identity


2nd half negative
raj@pilani.bits-pilani.ac.in
Hence the requirements:
1. T(r) should be single valued which ensures the

inverse transformation will exists

The monotonicity condition preserves the

increasing order from black to white in the

output image

2. Condition (b) guarantees the output gray levels

will be in the same range as that of input range


raj@pilani.bits-pilani.ac.in

The gray levels (r or s) in an image

random variable in the interval [0,1]

pr ( r ) & ps ( s ) are the PDFs of random


variables r and s, respectively

From the PDF theory of the random variable:

ps ( s ) ds  pr ( r ) dr
raj@pilani.bits-pilani.ac.in

To make the histogram uniform:

Put, ps ( s )  1

 ds  pr ( r ) dr
s r

 ds   p ( ) d
0 0
r

r
s   p ( ) d  T (r )
0
r
raj@pilani.bits-pilani.ac.in
r
s  T (r )  
0
pr ( ) d

Hence, the transformation function (T(r)) is equal


to the CDF of random variable, r

a)T(r) is singled valued and monotonically


increasing function. Hence the first condition
is satisfied.

b) Values of T(r) or s lie in the range [0,1]


raj@pilani.bits-pilani.ac.in

For discrete values,

nk
pr ( rk )  , k  0, 1, ..... L  1
n

k
sk  T ( rk )   p (r )
j0
r j

k nj
sk  T ( rk )  n
j 0
, for k  0, 1, ...., L  1
raj@pilani.bits-pilani.ac.in

This will do the histogram equalization


AUTOMATICALLY
raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

Problems:
raj@pilani.bits-pilani.ac.in
L-7, 29/1/2014
Histogram equalization is not full proof method
to achieve auto contrast
raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

Giving a transformation to the input image

where histogram of the output image is

predefined
raj@pilani.bits-pilani.ac.in

Original histogram
A predefined histogram

pr(r)

pz(z)

z
r
raj@pilani.bits-pilani.ac.in

How to transform???
raj@pilani.bits-pilani.ac.in

r  gray levels of the input image Random

s  gray levels of the output image variables

Let us define pr(r) and pz(z) are the PDFs of

the random variables r and s

s has the property::


r
s  T (r )  
0
pr ( ) d
raj@pilani.bits-pilani.ac.in
Discrete form::
k k nj
sk  T ( rk )   p (r )   n
j 0
r j
j 0

The random variable z has the property::

z
G( z )  
0
pz ( ) d  s
raj@pilani.bits-pilani.ac.in
Discrete form::
k
G( zk )   p (z )  s
i 0
z i k

Therefore,
G( z )  T ( r )

Hence,
1 1
z  G ( s )  G [T ( r )]
raj@pilani.bits-pilani.ac.in

STEPS for histogram matching

1. For a given input image, compute the histogram

pr(r)

r
raj@pilani.bits-pilani.ac.in

2. According to the definition of s, calculate

it from pr(r) Vs r curve

r
s  T (r )   p ( ) d
0
r

This will yield 


raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

3. For a given histogram ( Pz(z) Vs z ) ,

find out the variation of s Vs z

pz(z)

z
raj@pilani.bits-pilani.ac.in

z
s  G( z )   p ( ) d
0
z


raj@pilani.bits-pilani.ac.in

4. MAPPING of the variable r to z via s

For each value of rk , obtain the corresponding

value of sk from sk = T(rk) .

For each value of sk , obtain the corresponding

value of zk from sk = G(zk) by inverse

transformation.
raj@pilani.bits-pilani.ac.in

The last step:: s

sk
s

z zk z
r

r
raj@pilani.bits-pilani.ac.in

s
raj@pilani.bits-pilani.ac.in

Image averaging

Noisy image can be enhanced by averaging it

over a set of images

A noisy image (g(x,y)) can be expressed as

g( x , y )  f ( x , y )   ( x , y )
raj@pilani.bits-pilani.ac.in

where
f ( x, y)  Original image

 ( x, y)  Noise

If the noise (x,y) is uncorrelated, then


•The expected value of the noise (x,y) = 0
•The expected covariance of the
two random variables = 0
raj@pilani.bits-pilani.ac.in

{ gi ( x , y )}  Represents a set of noisy image

The average image is formed by,

K
1
g( x , y ) 
K
 g ( x, y)
i 1
i

1  K K

  
K  i 1
fi  
i 1
i 

raj@pilani.bits-pilani.ac.in

Take expectation either side

1  K K

E( g)   
K  i 1
E( fi )  
i 1
E ( i )

f i is a constant and same for all the images

 E{ f i }  f i

&
raj@pilani.bits-pilani.ac.in

E{i }  0

 E{ g( x, y)}  f ( x, y)
raj@pilani.bits-pilani.ac.in

K=8 K=16

K=64 K=128
raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

How to remove people from the image????


raj@pilani.bits-pilani.ac.in

How to remove vehicles from the image????


raj@pilani.bits-pilani.ac.in

Scaling of the gray levels during mathematical


operation

+ =

unscaled scaled
raj@pilani.bits-pilani.ac.in

unscaled
=
scaled
Mask filtering in spatial domain
raj@pilani.bits-pilani.ac.in

Subimage

Subimage  filter, mask, kernel, template, or window


raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

Subimage is a small matrix whose elements are

called COFFIECIENTS

Preferably, the size of the mask should be odd

If (m x n) size of the mask

Then, m=2a+1 and n=2b+1

a, b are integers
raj@pilani.bits-pilani.ac.in

Linear filter:

a b
g( x , y )    w( s, t ) f ( x  s, y  t )
sa t b

The coefficients w(x,y) are defined by the

user; depending on the nature of the filter

required
raj@pilani.bits-pilani.ac.in

eg.,

for an average filter of mask 3x3, each coefficient


should be 1/9

1 1 1

1 1 1
W= 1/9

1 1 1
raj@pilani.bits-pilani.ac.in

To perform the averaging, vary

x =0,1,2,….M-1

y =0,1,2…N-1
raj@pilani.bits-pilani.ac.in

1 2 1

1/16 2 4 2
W=

1 2 1

Weighted average
raj@pilani.bits-pilani.ac.in

Hence the general expression for avg.

a b

  w( s, t ) f ( x  s, y  t )
g( x , y )  sa t b
a b

  w( s, t )
sa t b
raj@pilani.bits-pilani.ac.in

Mask reaches the border:

(a) (b)

Padding
raj@pilani.bits-pilani.ac.in

Mask size

--, 3

5,9

15, 35
raj@pilani.bits-pilani.ac.in

•Averaging removes smaller details

•It leads to blurring


raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

Non-linear filters:

e.g., Median filter, variance filter

•Median filter is very powerful in removing random noise

with considerably less blurring than linear avg. filter

of similar size

•Median filters are effective for impulse noise.


raj@pilani.bits-pilani.ac.in

Find median of the set of 15 numbers

5, 7, 4, 5, 3, 6, 8, 7, 12, 1, 0, 4, 14, 1, 3

a) Arrange them as

0, 1, 1, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8, 12, 14

Median = 5
raj@pilani.bits-pilani.ac.in

Find median of the set of 14 numbers

87, 55, 67, 87, 98, 80, 45, 65, 75, 67, 87, 92, 87, 63

Arrange them

45, 55, 63, 65, 67, 67, 75, 80, 87, 87, 87, 87, 92, 98

Median = Avg(75,80) = 77.5


raj@pilani.bits-pilani.ac.in
raj@pilani.bits-pilani.ac.in

Noisy image Median filtered image


(3x3 mask)
raj@pilani.bits-pilani.ac.in

Comparison
raj@pilani.bits-pilani.ac.in

a) Max filter

The pixel value is replaced by the maximum calculated


from the neighborhood.

b) Min Filter

The pixel value is replaced by the minimum calculated


from the neighborhood.

c) Mid point filter

The pixel value is replaced by the 0.5*(min+max)


calculated from the neighborhood.

You might also like