0% found this document useful (0 votes)
10 views106 pages

Intensity

Uploaded by

hi.ar.008
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)
10 views106 pages

Intensity

Uploaded by

hi.ar.008
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

Digital Image Processing

Intensity Transformations
and
Spatial Filtering
Background

 Spatial domain process


g ( x, y )  T [ f ( x, y )]

 where f ( x, y ) is the input image, g ( x, y )


is the processed image, and T is an
operator on f, defined over some
neighborhood of ( x, y )
 Neighborhood about a point
 Gray-level transformation function
s  T (r )
 where r is the gray level of f ( x, y ) and
s is the gray level of g ( x, y ) at any
point ( x, y )
 Contrast enhancement
 For example, a thresholding function
 Masks (filters, kernels, templates,
windows)
 A small 2-D array in which the values
of the mask coefficients determine the
nature of the process
Some Basic Gray Level
Transformations
 Image negatives
s  L 1 r
 Enhance white or gray details
 Log transformations
s  c log(1  r )
 Compress the dynamic range of images
with large variations in pixel values
 From the range 0-1.5  106 to the range
0 to 6.2
 Power-law transformations
 
 s  cr or s  c(r   )
   1 maps a narrow range of dark
input values into a wider range of
output values, while   1 maps a
narrow range of bright input values into
a wider range of output values
  : gamma, gamma correction
 Monitor,   2.5
 Piecewise-linear transformation
functions
 The form of piecewise functions can be
arbitrarily complex
 Contrast stretching
 Gray-level slicing
 Bit-plane slicing
Image Enhancement: Histogram
Based Methods
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 h(rk )  nk
nk
Normalized histogram p (rk ) 
n
nk: Number of pixels with gray value rk

n : total Number of pixels in the image


rk : kth gray level of a pixel

The function p(rk) represents the fraction of the total number


of pixels with gray value rk.
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 )
Some Typical Histograms
The shape of a histogram provides useful information for
contrast enhancement.

Dark image
Bright image

Low contrast image


High contrast image
Histogram Examples (cont…)

A selection of images and


their histograms
Notice the relationships
between the images and
their histograms
Note that the high contrast
image has the most
evenly spaced histogram
Histogram Equalization

Spreading out the frequencies in an image (or equalising the image) is a


simple way to improve dark or washed out images.

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.
 Assume that:

(1) T(r) is a monotonically increasing function for


0 r 1 (preserves order from black to white).

(2) T(r) maps [0,1] into [0,1] (preserves the range of


allowed Gray values).
 Histogram equalization
s  T (r ), 0  r  1
r  T 1 ( s ), 0  s  1
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.
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.


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
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.
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
sk  T (rk )   pin (r j ) 0  k  L 1
j 0
 Probability density functions (PDF)
dr
ps ( s )  pr ( r )
ds
r
s  T (r )  ( L  1)  pr ( w)dw
0

ds dT (r ) d  r   ( L  1) p (r )
dr

dr
 ( L  1)

dr  0
p r ( w) dw

 r

1
ps ( s ) 
L 1
k k nj
sk  T (rk )  ( L  1) pr (rj ) ( L  1) , k  0,1,2,..., L  1
j 0 j 0 n
 Histogram matching (specification)
r
s  T (r )  ( L  1)  pr ( w)dw
0
z
G ( z )  ( L  1)  p z (t )dt  s
0

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

p z (z ) is the desired PDF


k k nj
sk  T (rk )  ( L  1) pr (rj )  ( L  1) , k  0,1,2,..., L  1
j 0 j 0 n
k
vk  G ( zk )  ( L  1) p z ( zi ) sk , k  0,1,2,..., L  1
i 0

1
z k  G [T (rk )], k  0,1,2,..., L  1
 Histogram matching
 Obtain the histogram of the given
image, T(r)
 Precompute a mapped level sk for each
level rk
 Obtain the transformation function G
from the given p z (z )
 Precompute z k for each value of sk
 Map rk to its corresponding level sk ;
then map level sk into the final level z k
 Local enhancement
 Histogram using a local neighborhood,
for example 7*7 neighborhood
 Histogram using a local 3*3
neighborhood
 Use of histogram statistics for
image enhancement
 r denotes a discrete random variable
 p (ri ) denotes the normalized
histogram component corresponding to
the ith value of r
 Mean L 1
m   ri p(ri )
i 0
 The nth moment
L 1
 n (r )   (ri  m) p(ri )
n

i 0

 The second moment


L 1
 2 (r )   (ri  m) p(ri )
2

i 0
 Global enhancement: The global mean
and variance are measured over an
entire image
 Local enhancement: The local mean
and variance are used as the basis for
making changes
 rs ,t is the gray level at coordinates
(s,t) in the neighborhood
 p(rs ,t ) is the neighborhood normalized
histogram component
 mean:
mS xy  r
( s ,t )S xy
s ,t p(rs ,t )
 local variance
 2
S xy   [r
( s ,t )S xy
s ,t  mS xy ] p(rs ,t )
2
 E , k0 , k1 , k 2 are specified parameters
 M G is the global mean
 DG is the global standard deviation
 Mapping

 if mS xy  k0 M G
 E  f ( x, y )
g ( x, y )   and k1 DG   S xy  k 2 DG
 f ( x, y ) otherwise

Fundamentals of Spatial Filtering

 The Mechanics of Spatial Filtering

R  w(1,1) f ( x  1, y  1) 
w(1,0) f ( x  1, y )   
w(0,0) f ( x, y )   
w(1,0) f ( x  1, y ) 
w(1,1) f ( x  1, y  1)
 Image size: M N
 Mask size: mn
a b
g ( x, y )    w(s, t ) f ( x  s, y  t )
s   at   b

 a  (m  1) / 2 and b  (n  1) / 2
 x  0,1,2,..., M  1 and y  0,1,2,..., N  1
 Spatial Correlation and Convolution
 Vector Representation of Linear
Filtering
R  w1 z1  w2 z 2  ...  w9 z9
9
  wi zi
i 1
Smoothing Spatial Filters

 Smoothing Linear Filters


 Noise reduction
 Smoothing of false contours
 Reduction of irrelevant detail
1 9
R   zi
9 i 1
a b

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

  w(s, t )
s   at   b
 Order-statistic filters
 median filter: Replace the value of a
pixel by the median of the gray levels
in the neighborhood of that pixel
 Noise-reduction
Sharpening Spatial Filters

 Foundation
 The first-order derivative
f
 f ( x  1)  f ( x)
x
 The second-order derivative

 f
2
 f ( x  1)  f ( x  1)  2 f ( x)
x 2
 Use of second derivatives for
enhancement-The Laplacian
 Development of the method

 2
f  2
f
 f  2  2
2

x y
 f
2
 f ( x  1, y )  f ( x  1, y )  2 f ( x, y )
x 2

 f
2
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y )
y 2
 f  [ f ( x  1, y )  f ( x  1, y )  f ( x, y  1) 
2

f ( x, y  1)]  4 f ( x, y )
 if the center coefficient
 f ( x, y )   2 f ( x, y ) of the Laplacian mask

 is negative
g ( x, y )  
if the center coefficient

 f ( x, y )   f ( x, y ) of the Laplacian mask
2


 is positive
 Simplifications

g ( x, y )  f ( x, y )  [ f ( x  1, y )  f ( x  1, y )  f ( x, y  1) 
f ( x, y  1)]  4 f ( x, y )
 5 f ( x, y )  [ f ( x  1, y )  f ( x  1, y )  f ( x, y  1) 
f ( x, y  1)]
 Unsharp masking and highboost
filtering
 Unsharp masking
 Substract a blurred version of an image
from the image itself

g mask ( x, y )  f ( x, y )  f ( x, y )

 f ( x, y ) : The image, f ( x, y ) : The


blurred image
g ( x, y )  f ( x, y )  k * g mask ( x, y ) ,k 1
 High-boost filtering

g ( x, y )  f ( x, y )  k * g mask ( x, y ) ,k 1
 Using first-order derivatives for
(nonlinear) image sharpening—The
gradient
 f 
Gx   x 
f      f 
G y   
 y 
 The magnitude is rotation invariant
(isotropic)


f  mag(f )  G  G 2
x
2
y 
1
2

1
 f  2  f  2  2

      
 x   y  

f  G x  G y
 Computing using cross differences,
Roberts cross-gradient operators
G x  ( z 9  z5 ) and G y  ( z8  z 6 )


f  ( z9  z5 )  ( z8  z6 )
2 2

1
2

f  z9  z5  z8  z6
 Sobel operators
 A weight value of 2 is to achieve some
smoothing by giving more importance to
the center point

f  ( z7  2 z8  z9 )  ( z1  2 z 2  z3 )
 ( z3  2 z6  z9 )  ( z1  2 z 4  z7 )
Combining Spatial Enhancement
Methods

 An example
 Laplacian to highlight fine detail
 Gradient to enhance prominent edges
 Smoothed version of the gradient
image used to mask the Laplacian
image
 Increase the dynamic range of the gray
levels by using a gray-level
transformation

You might also like