You are on page 1of 50

# Image Enhancement in the

Spatial Domain II
Review: gray level transformations

## For this image,

what transform
should we apply?
Histogram Processing
 Histogram equalization
 Histogram matching
 Local enhancement
 Use of histogram statistics
Histogram
 Statistics of the pixel gray-levels of an image
 h(rk)=nk : histogram
no. of
occurrence

gray level
Obtain contrast information
from histogram
Histogram: implementation issue
 Divide the range of gray levels (ex. 0~255)
 Number of bins
 Position of bins specified in a vector

10 bins
5 bins
Histogram: normalization

## no. of no. of occurrence

=prob.
occurrence total pixels

## gray level gray level

Histogram equalization 均化
 Goal: produce an uniform histogram
 Find a transformation: s=T(r)

uniform

0 1 0 1
Histogram equalization(cont.)
Cumulative function of
1 histogram

## 0.5 Ideal cumulative func.

Prob. 0.5

0.5

0 1 0 0.5 1
Ideal uniform histogram
Histogram equalization:
discrete solution
 Probability (normalized histogram) of gray
level rk
 p(rk)=nk/n, k=0,1,2,…, L-1
 Discrete version of CDF (cumulative
distribution function)
k k nj
sk  T (rk )   pr (rj )   <1
j 0 j 0 n
Example: histogram equalization
Histogram Processing
 Histogram equalization
 Histogram matching
 Local enhancement
 Use of histogram statistics
Histogram matching: original
image
Histogram equalization result
Histogram
Equalization
function

Equalized
histogram
After equalization
Histogram matching
 The desired shape of histogram is specified
(not necessarily uniform)
 Derivation of histogram matching function:

z=G-1(T(r))
z s r
desired uniform input
z=G-1(s) s=T(r)
histogram
equalization

histogram
equalization
s=G(z)
Original -> uniform desire -> uniform
(equalization) (equalization)

Inverse
function
of G
Histogram matching result
Desired histogram

After histogram
matching

G-1
Histogram Processing
 Histogram equalization
 Histogram matching
 Local enhancement
 Use of histogram statistics
Local enhancement
 Global: entire image
 Local: neighborhood of each pixel

## Original image Global equalization 7x7 neighborhood

local equalization
Histogram statistics
 Take pixel value r as a random variable
Normalized histogram of an image
=> probability distribution function of r

##  Some measure about pdf

L 1
m   ri p ( ri ) mean
i 0
L 1
 2 (r )   (ri  m) 2 p (ri ) variance
i 0

## mean => average gray level

variance => average contrast
Histogram statistics (cont.)
 Local measurement: Sxy neighborhood

mS xy  r
( s ,t )S xy
s ,t p(rs ,t ) mean in Sxy

 (r ) 
2
S xy  (r
( s ,t )S xy
s ,t  mS xy ) p(rs ,t )
2
variance in Sxy
Application of histogram statistics:
example
Globally, this image is light

## However, some dark

background object is
unseen

Histogram statistics: example
Calculate local statistics in 3x3 region
local mean local standard deviation
Histogram statistics: example
 Local enhancement 像素平均值小 但是標準差大
E  f ( x, y )k1 if mS xy  k0 M G and DG   S xy  k1 DG
g ( x, y )  
 f ( x, y ) otherwise

enhanced
pixels
Histogram statistics: example

original enhanced
Outline: spatial domain
 Histogram processing
 Spatial filtering
 Smoothing filter
 Ordered statistics filter
 Sharpening filter
Basics of spatial filtering

 g(x,y)=T[ f(x,y) ]
 T operates on a
neighborhood

X (product) output

underlying neighborhood
Basics of spatial filtering
 Mathematical formula
a b
g ( x, y )    w(s, t ) f ( x  s, y  t )
s   at   b
convolution

 Border issues
 Operate inside only
 extension
Smoothing spatial filtering
 Used for blurring and for noise reduction
 Smoothing linear filters
 Average filters, low-pass filters

## average filter weighted filter 這兩個效果差不多

original 3x3

noise
reduced

5x5 9x9

small area
blended into
background

15x15 35x35
border
effects
Smoothing: example

## 15x15 smoothing thresholding

Order-statistics filters
 Pixel neighborhood
f1 f2 f3
f4 f5 f6
f7 f8 f9
sort
f4 f3 f7 f6 f8 f2 f1 f9 f5
increasing order

## min median max

filter filter filter
remove isolated
high(low) pixels
Median filter: example

## original 3x3 average 3x3 median

salt-and-pepper noise
Outline: spatial domain
 Histogram processing
 Spatial filtering 空間濾波
 Smoothing filter
 Ordered statistics filter
 Sharpening filter
Sharpening
filtering:
example
original Edge detection

scaled sharpened
Sharpening spatial filters
 Goal
 highlight fine detail in an image
 Spatial differentiation 微分
 Digital implementation => difference 差分
 de-emphasize regions with slowly varying gray
levels
smooth

 1  ( 1) '

 2  ( 1)2 ''
Sharpening: foundation
 First and second-order derivatives in digital
form => difference
f
 f ( x  1)  f ( x) 一次微分
x
2 f
 [ f ( x  1)  f ( x)]  [ f ( x)  f ( x  1)] 二次微分
x 2

 f ( x  1)  f ( x  1)  2 f ( x)
2nd derivatives for image
 2-D 2nd derivatives => Laplacian
 2
f  2
f
 f  2  2
2

x y
=>discrete formulation
 2 f  [ f ( x  1, y )  f ( x  1, y )  2 f ( x, y )]
 [ f ( x, y  1)  f ( x, y  1)  2 f ( x, y )]
 [ f ( x  1, y )  f ( x  1, y )  f ( x, y  1)  f ( x, y  1)]  4 f ( x, y )
Definition of 2nd derivatives in
450 rotation
900 rotation invariant
invariant (include
Diagonals)

- - - -

- 4 - - 8 -

- - - -
Laplacian filtering: example

## original Laplacian filtered image

Sharpened result = original +
Laplacian filtered image
 f ( x, y)   2 f ( x, y) if center coeff. of the mask is negative
g ( x, y)  
 f ( x, y )   2
f ( x, y) if center coeff. of the mask is positive

## original image filtered image

Laplacian
filtering:
example

original Laplacian

scaled sharpened
original

right
left
Gx   x 
f      f 
G y   
 y 

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

f  mag (f )       
 x   y  

## Simplified form => f  G x  G y

Definition of 1st derivative in