You are on page 1of 38

CSE 7448 – Image Processing

Chapter 3. Intensity Transformation


and Spatial Filtering
Dec 2019

Prof. Chung/Worku J. (PhD)


Last week
 Spatial and Transform domain

 Intensity Transformation Functions

 Image Histogram/Processing

 Histogram Equalization

 Histogram Matching (Specification)

 Summary

2
Outline
 Local Histogram processing

 Filtering in spatial domain

 Smoothing and sharpening in spatial domain

3
3.3.3 Local Histogram Processing

Define a neighborhood and move its center from pixel to


pixel

At each location, the histogram of the points in the


neighborhood is computed. Either histogram equalization or
histogram specification transformation function is obtained

Map the intensity of the pixel centered in the neighborhood

Move to the next location and repeat the procedure

4
3.3.3 Local Histogram Processing: Example
(P 161)

5
3.3.4 Using Histogram Statistics
for Image Enhancement
The nth moment of r about its mean: (from section 2.6.8)
L 1
un (r )   (ri  m) n p (ri )
i 0
Average Intensity m:
L 1 M 1 N 1
1
m   ri p (ri ) 
MN
  f ( x, y )
x 0 y 0
i 0
Variance = the second moment:
L 1 M 1 N 1
1
  u2 (r )   (ri  m) p(ri )   f ( x, y )  m 
2 2 2

MN x 0 y 0
i 0

6
Using Histogram Statistics for Image
Enhancement
Let S denote a neighborhood of any pixel (x,y):
example: S size can be 3x3
Local average intensity
L 1
msxy   ri psxy (ri )
i 0

sxy denotes a neighborhood

Local variance
L 1
 s2xy   (ri  msxy ) 2 psxy (ri ) 7
i 0
3.4 Spatial Filtering (p 166)

A spatial filter consists of


(a) a neighborhood, and
(b) a predefined operation

- “Filtering” refers to accepting (passing) or rejecting certain frequency


components. “Low pass filter” passes low frequencies.
Main role is to enhance image quality such as reducing noises.
- spatial filter: is called also mask, kernel, template, and window.
- There is one-to-one correspondence between linear filters
and filters in frequency domain.
- Linear spatial filtering of an image of size MxN with a filter of
size mxn is given by the expression
a b
g ( x, y )    w(s, t ) f ( x  s, y  t )
s  a t  b
8
Spatial Filtering

Spatial filter
mask

Image section
under filter 9
Spatial Correlation

The correlation of a filter w( x, y ) of size m  n


with an image f ( x, y ), denoted as w( x, y ) f ( x, y )
a b
w( x, y ) f ( x, y )    w(s, t ) f ( x  s, y  t )
s  a t  b

a=(m-1)/2, b=(m-1)/2
Ex) an image of size MxN with a filter of size mxn
m=3, n=3  a=(3-1)/2= 2/2=1, b=1

10
Spatial Convolution

The convolution of a filter w( x, y ) of size m  n


with an image f ( x, y ), denoted as w( x, y ) f ( x, y )

a b
w( x, y ) f ( x, y )    w(s, t ) f ( x  s, y  t )
s  a t  b
s= -1, t= -1,  w(-1,-1) f(x+1, y+1)
-1, 0,  w(-1, 0) f(x+1, y)
-1, 1,  w(-1, 1) f(x+1, y-1)
0, -1,  w( 0,-1) f(x, y+1)
0, 0,  w( 0, 0) f(x, y)
0, 1,  w( 0, 1) f(x, y-1)
1, -1,  w( 1,-1) f(x-1, y+1)
1, 0,  w( 1, 0) f(x-1, y) 11

1, 1,  w( 1, 1) f(x-1, y-1)
Correlation

Convolution

12
13
Smoothing Spatial Filters

Smoothing filters are used for blurring and for noise


reduction

Blurring is used in removal of small details and bridging of


small gaps in lines or curves

Smoothing spatial filters include linear filters and nonlinear


filters.

14
Spatial Smoothing Linear Filters

The general implementation for filtering an M  N image


with a weighted averaging filter of size m  n is given
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

where m  2a  1, n  2b  1.

15
Two Smoothing Averaging Filter Masks

16
1 1 1 1 1
1 1 1
1 1 1 1 1
1 1 1
1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1

1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
17
Example: Gross Representation of Objects

18
Order-statistic (Nonlinear) Filters

— Nonlinear

— Based on ordering (ranking) the pixels contained in the


filter mask

— Replacing the value of the center pixel with the value


determined by the ranking result

E.g., median filter, max filter, min filter

- median filter: 1) sorting 2) select the value in the middle


- max filter: find the largest value in the filter section

19
Example: Use of Median Filtering for Noise Reduction

20
Sharpening Spatial Filters

► Foundation

► Laplacian Operator

► Unsharp Masking and Highboost Filtering

► Using First-Order Derivatives for Nonlinear Image


Sharpening — The Gradient

21
Sharpening Spatial Filters: Foundation

► The first-order derivative of a one-dimensional function f(x)


is the difference

f
 f ( x  1)  f ( x)
x

► The second-order derivative of f(x) as the difference

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

22
23
Sharpening Spatial Filters: Laplace Operator

The second-order isotropic derivative operator is the


Laplacian for a function (image) f(x,y)

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

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

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

 2 f  f ( x  1, y )  f ( x  1, y )  f ( x, y  1)  f ( x, y  1)
- 4 f ( x, y )
24
Sharpening Spatial Filters: Laplace Operator

25
Sharpening Spatial Filters: Laplace Operator

Image sharpening in the way of using the Laplacian:

g ( x, y )  f ( x, y )  c  2 f ( x, y ) 
where,
f ( x, y ) is input image,
g ( x, y ) is sharpenend images,
c  -1 if  2 f ( x, y ) corresponding to Fig. 3.37(a) or (b)
and c  1 if either of the other two filters is used.

26
27
Unsharp Masking and Highboost Filtering

► Unsharp masking
Sharpen images consists of subtracting an unsharp (smoothed)
version of an image from the original image
e.g., printing and publishing industry

► Steps
1. Blur the original image

2. Subtract the blurred image from the original

3. Add the mask to the original

28
Unsharp Masking and Highboost Filtering

Let f ( x, y ) denote the blurred image, unsharp masking is


g mask ( x, y )  f ( x, y )  f ( x, y )
Then add a weighted portion of the mask back to the original
g ( x, y )  f ( x, y )  k * g mask ( x, y ) k 0

when k  1, the process is referred to as highboost filtering.

29
Unsharp Masking: Demo

30
Unsharp Masking and Highboost Filtering: Example

31
Image Sharpening based on First-Order Derivatives

For function f ( x, y ), the gradient of f at coordinates ( x, y )


is defined as
 f 
 g x   x 
f  grad( f )      
 g y   f 
 y 

The magnitude of vector f , denoted as M ( x, y )


Gradient Image M ( x, y )  mag(f )  g x 2  g y 2
32
Image Sharpening based on First-Order Derivatives

The magnitude of vector f , denoted as M ( x, y )


M ( x, y )  mag(f )  g x 2  g y 2

M ( x, y ) | g x |  | g y |

z1 z2 z3
M ( x, y ) | z8  z5 |  | z6  z5 |
z4 z5 z6
z7 z8 z9
33
Image Sharpening based on First-Order Derivatives

Roberts Cross-gradient Operators


M ( x, y ) | z9  z5 |  | z8  z6 |

Sobel Operators
M ( x, y ) | ( z7  2 z8  z9 )  ( z1  2 z2  z3 ) |
z1 z2 z3  | ( z3  2 z6  z9 )  ( z1  2 z4  z7 ) |
z4 z5 z6
z7 z8 z9
34
Image Sharpening based on First-Order Derivatives

f’(x)=f(x+1)-f(x)
f’(y)=f(y+1)-f(y)

x 35
Example

36
Example:

Combining
Spatial
Enhancement
Methods

Goal:

Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail

37
Example:

Combining
Spatial
Enhancement
Methods

Goal:

Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail

38

You might also like