0% found this document useful (0 votes)
17 views89 pages

IP - 2 - Spatial Filtering

Image Process
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)
17 views89 pages

IP - 2 - Spatial Filtering

Image Process
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
You are on page 1/ 89

Danang University of Science and Technology (DUT)

Image Processing
Lecture 2
Intensity transformation and Spatial
Filtering
Outline

 Gray-level transformation

 Histogram processing

 Spatial Filtering

2
Outline

 Gray-level transformation

 Histogram processing

 Spatial Filtering

3
Spatial Domain vs. Transform
Domain
 Spatial domain
image plane itself, directly process the intensity values of
the image plane

 Transform domain
process the transform coefficients, not directly process
the intensity values of the image plane

4
Spatial Domain Process

𝐠 𝐱, 𝐲 = 𝐓[𝐟(𝐱, 𝐲)]

f(x,y): input image


g(x,y): output image
T: an operator of f defined over a neighborhood
of point (x,y)

5
Spatial Domain Process

6
Spatial Domain Process

Intensity transformation function: s = T(r)

7
Some Basic Intensity
Transformation Functions

8
Image Negatives

Image negatives:
s=L–1-r

9
Example: Image Negatives

10
Log Transformations

Log Transformations:
s = c log(1+r)

11
Example: Log Transformations

12
Power-Law (Gamma)
Transformations

𝐬 = 𝐜𝐫 𝛄

13
Example: Gamma Transformations

14
Example: Gamma Transformations

Cathode ray tube


(CRT) devices have
an intensity-to-
voltage response
that is a power
function, with
exponents varying
𝟏 from approximately
𝐬=𝐜 𝐫 𝟐.𝟓
1.8 to 2.5

15
Example: Gamma Transformations

16
Example: Gamma Transformations

17
Piecewise-Linear Transformations

 Contrast Stretching
Expands the range of intensity levels in an image so
that it spans the full intensity range of the recording
medium or display device.
 Intensity-level Slicing
Highlighting a specific range of intensities in an image
often is of interest.

18
19
20
Bit-plane Slicing

21
Bit-plane Slicing

22
Bit-plane Slicing

23
Outline

 Gray-level transformation

 Histogram processing

 Spatial Filtering

24
Histogram Processing

 Histogram Equalization

 Histogram Matching

 Local Histogram Processing

 Using Histogram Statistics for Image Enhancement

25
Histogram
What is histogram?

Histogram h(rk) = nk
rk is the kth intensity value
nk is the number of pixels in the image with intensity rk

𝐧𝐤
Normalized histogram 𝐩 𝐫𝐤 =
𝐌𝐍
nk is the number of pixels in the image of size MxN
with intensity rk

26
Histogram
Example :

Lena, 512 x 512 Histogram


27
28
Histogram

Remarks:

Consider a histogram as a probability density function


(pdf)

- Advantages ?

- Disadvantages ?

29
Histogram Equalization
The intensity levels in an image may be viewed as
random variables in the interval [0, L-1]
Let pr(r) and ps(s) denote the probability density function
(pdf) of random variables r and s

30
Histogram Equalization
𝐬=𝐓 𝐫 𝟎≤𝐫≤𝐋−𝟏
 T(r) is a strictly monotonically increasing function in
the interval 𝟎 ≤ 𝐫 ≤ 𝐋 − 𝟏
 𝟎 ≤ 𝐓(𝐫) ≤ 𝐋 − 𝟏 for 𝟎 ≤ 𝐫 ≤ 𝐋 − 𝟏

31
Histogram Equalization
𝐬=𝐓 𝐫 𝟎≤𝐫≤𝐋−𝟏
 T(r) is a strictly monotonically increasing function in
the interval 𝟎 ≤ 𝐫 ≤ 𝐋 − 𝟏
 𝟎 ≤ 𝐓(𝐫) ≤ 𝐋 − 𝟏 for 𝟎 ≤ 𝐫 ≤ 𝐋 − 𝟏

T(r) is continuous and differentiable.


(Property of
𝐩𝐬 𝐬 𝐝𝐬 = 𝐩𝐫 𝐫 𝐝𝐫 the pdf for a
RV s=T(r))

32
Histogram Equalization
𝐫
Choose 𝐬 = 𝐓 𝐫 = (𝐋 − 𝟏) 𝐩𝐫 𝐰 𝐝𝐰
𝟎

𝐫
𝐝𝐬 𝐝𝐓(𝐫) 𝐝
= = 𝐋−𝟏 𝐩𝐫 𝐰 𝐝𝐰 = (𝐋 − 𝟏)𝐩𝐫 (𝐫)
𝐝𝐫 𝐝𝐫 𝐝𝐫 𝟎

𝐩𝐫 𝐫 𝐝𝐫 𝐩𝐫 𝐫 𝐩𝐫 𝐫 𝟏
𝐩𝐬 𝐬 = = 𝐝𝐬 =
𝐝𝐬 (𝐋 − 𝟏)𝐩𝐫 (𝐫) = 𝐋 − 𝟏
𝐝𝐫

Uniform
33
Example
Suppose that the (continuous) intensity values
in an image have the PDF

 2r
 , for 0  r  L-1
pr (r )   ( L  1) 2

 0, otherwise

Find the transformation function for equalizing


the image histogram.

34
Example

Continuous case:
r
s  T (r )  ( L  1)  pr ( w)dw
0

35
Histogram Equalization
𝐫
Continuous case: 𝐬 = 𝐓 𝐫 = (𝐋 − 𝟏) 𝐩𝐫 𝐰 𝐝𝐰
𝟎

Discrete values:
𝐤

𝐬𝐤 = 𝐓 𝐫𝐤 = 𝐋 − 𝟏 𝐩𝐫 𝐫𝐣
𝐣=𝟎
𝐤 𝐤
𝐧𝐣 𝐋−𝟏
= 𝐋−𝟏 = 𝐧𝐣 𝐤 = 𝟎, 𝟏, . . , 𝐋 − 𝟏
𝐌𝐍 𝐌𝐍
𝐣=𝟎 𝐣=𝟎

36
Example: Histogram Equalization
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096)
has the intensity distribution shown in following table.
Get the histogram equalization transformation function and give the
ps(sk) for each sk.

37
Example:
Histogram
Equalization
Rounded
value

0
s0  T (r0 )  7 pr (rj )  7  0.19  1.33 1
j 0
1
s1  T (r1 )  7 pr (rj )  7  (0.19  0.25)  3.08 3
j 0
s2  4.55  5 s3  5.67  6
s4  6.23  6 s5  6.65  7
s6  6.86  7 s7  7.00  7 38
Example: Histogram Equalization

39
40
Histogram Matching

Histogram matching (histogram specification): generate


a processed image that has a specified histogram

Ir, pr, and pz known => find Iz

Ir, pr Iz, pz

Is, uniform Specified histogram


41
Histogram Matching
Let pr(r) and pz(z) denote the continuous probability density
functions of the variables r and z. pz(z) is the specified
probability density function.
Let s be the random variable with the probability:
𝐫
𝐬 = 𝐓 𝐫 = (𝐋 − 𝟏) 𝐩𝐫 𝐰 𝐝𝐰
𝟎
Define a random variable z with the probability
𝐳
𝐆 𝐳 = 𝐋−𝟏 𝐩𝐳 𝐭 𝐝𝐭 = 𝐬
𝟎
Compute:
𝐳 = 𝐆−𝟏 𝐬 = 𝐆−𝟏 𝐓(𝐫)
42
Histogram Matching - procedure
 Obtain pr(r) from the input image and then obtain the
values of s
𝐫
𝐬 = (𝐋 − 𝟏) 𝐩𝐫 𝐰 𝐝𝐰
𝟎
 Use the specified PDF and obtain the transformation
function G(z)
𝐳
𝐆 𝐳 = 𝐋−𝟏 𝐩𝐳 𝐭 𝐝𝐭 = 𝐬
𝟎
 Mapping from s to z
𝐳 = 𝐆−𝟏 𝐬
43
Histogram Matching: Example
Assuming continuous intensity values, suppose that an image has
the intensity PDF
 2r
 , for 0  r  L -1
pr (r )   ( L  1) 2

 0, otherwise

Find the transformation function that will produce an image whose
intensity PDF is
 3z 2
 , for 0  z  ( L -1)
pz ( z )   ( L  1) 3

 0, otherwise

44
Histogram Matching: Example
Find the histogram equalization transformation for the input image
2
r r 2w r
s  T (r )  ( L  1)  pr (w)dw  ( L  1)  dw 
0 0 ( L  1) 2
L 1

Find the histogram equalization transformation for the specified histogram

z z 3t 2 z3
G( z )  ( L  1)  pz (t )dt  ( L  1)  dt  s
0 0 ( L  1) 3
( L  1) 2

The transformation function


1/3
1/3  2 r
2
 2 1/3
z  ( L  1) s 
2
 ( L  1)   ( L  1)r 
 L  1 
45
Histogram Matching: Discrete
Cases
 Obtain pr(rj) from the input image and then obtain the
values of sk, round the value to the integer range [0, L-1].
𝐤 𝐤
𝐋−𝟏
𝐬𝐤 = 𝐓 𝐫𝐤 = 𝐋 − 𝟏 𝐩𝐫 𝐫𝐣 = 𝐧𝐣
𝐌𝐍
𝐣=𝟎 𝐣=𝟎

 Use the specified PDF and obtain the transformation


function G(zq), round the value to the integer range [0, L-1].
𝐪

𝐆 𝐳𝐪 = (𝐋 − 𝟏) 𝐩𝐳 𝐳𝐢 = 𝐬𝐤
𝐢=𝟎

 Mapping from sk to zq: 𝐳𝐪 = 𝐆−𝟏 (𝐬𝐤 ) 46


Example: Histogram Matching
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096)
has the intensity distribution shown in the following table (on the left).
Get the histogram transformation function and make the output
image with the specified histogram, listed in the table on the right.

47
Example: Histogram
Matching
Obtain the scaled histogram-equalized values,

s0  1, s1  3, s2  5, s3  6, s4  7,
s5  7, s6  7, s7  7.
Compute all the values of the transformation function G,
0
G( z0 )  7 pz ( z j )  0.00 0
j 0

G ( z1 )  0.00 0 G ( z2 )  0.00  0
G ( z3 )  1.05  1 G ( z4 )  2.45  2
G ( z5 )  4.55  5 G ( z6 )  5.95  6
G ( z7 )  7.00  7

48
Example: Histogram Matching

49
Example: Histogram Matching
Obtain the scaled histogram-equalized values,

s0  1, s1  3, s2  5, s3  6, s4  7,
s5  7, s6  7, s7  7.
Compute all the values of the transformation function G,
0
G( z0 )  7 pz ( z j )  0.00 0
j 0

G ( z1 )  0.00 0 G ( z2 )  0.00  0
G ( z3 )  1.05  1 s0 G ( z4 )  2.45  2 s1
G ( z5 )  4.55  5 s2 G ( z6 )  5.95  6 s3
G ( z7 )  7.00  7 s4 s5 s6 s7

50
Example: Histogram Matching
s0  1, s1  3, s2  5, s3  6, s4  7, rk  zq
s5  7, s6  7, s7  7.
03
1 4
rk
0
25
1 36
2 47
3
4
57
5 67
6 77
7 51
Example: Histogram Matching

52
Example: Histogram Matching

53
z = G-1(s)

54
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

55
Local Histogram Processing:
Example

56
Using Histogram Statistics for
Image Enhancement
 Average Intensity
𝐋−𝟏 𝐌−𝟏 𝐍−𝟏
𝟏
𝐦= 𝐫𝐢 𝐩 𝐫𝐢 = 𝐟(𝐱, 𝐲)
𝐌𝐍
𝐢=𝟎 𝐱=𝟎 𝐲=𝟎

𝐋−𝟏

𝐮𝐧 (𝐫) = 𝐫𝐢 − 𝐦 𝐧 𝐩(𝐫𝐢 )
𝐢=𝟎
 Variance
𝐋−𝟏 𝐌−𝟏 𝐍−𝟏
𝟏
𝛔𝟐 = 𝐮𝟐 𝐫 = 𝐫𝐢 − 𝐦 𝟐𝐩 𝐫𝐢 = 𝐟 𝐱, 𝐲 − 𝐦 𝟐
𝐌𝐍
𝐢=𝟎 𝐱=𝟎 𝐲=𝟎 57
Using Histogram Statistics for
Image Enhancement
 Local Average Intensity
𝐋−𝟏

𝐦𝐬𝐱𝐲 = 𝐫𝐢 𝐩𝐬𝐱𝐲 𝐫𝐢
𝐢=𝟎
𝐬𝐱𝐲 denotes a neighborhood
 Local Variance
𝐋−𝟏
𝟐
𝛔𝟐 𝐬𝐱𝐲 = 𝐫𝐢 − 𝐦𝐬𝐱𝐲 𝐩𝐬𝐱𝐲 𝐫𝐢
𝐢=𝟎
58
Outline

 Gray-level transformation

 Histogram processing

 Spatial Filtering

59
Introduction
 A spatial filter consists of a neighborhood and a
predefined operation
 Linear spatial filtering of an image of size MxN with a
filter of size mxn is given by the expression
𝐚 𝐛

𝐠 𝐱, 𝐲 = 𝐰 𝐬, 𝐭 𝐟(𝐱 + 𝐬, 𝐲 + 𝐭)
𝐬=−𝐚 𝐭=−𝐛

a mask

60
Introduction

61
Spatial Correlation

 The correlation of a filter w(x,y) of size mxn with an


image f(x,y) is denoted as 𝐰 𝐱, 𝐲 ∗ 𝐟(𝐱, 𝐲)
𝐚 𝐛

𝐰 𝐱, 𝐲 ∗ 𝐟 𝐱, 𝐲 = 𝐰 𝐬, 𝐭 𝐟(𝐱 + 𝐬, 𝐲 + 𝐭)
𝐬=−𝐚 𝐭=−𝐛

62
Spatial Convolution

 The convolution of a filter w(x,y) of size mxn with an


image f(x,y) is denoted as 𝐰(𝐱, 𝐲) ⋆ 𝐟(𝐱, 𝐲)
𝐚 𝐛

𝐰(𝐱, 𝐲) ⋆ 𝐟 𝐱, 𝐲 = 𝐰 𝐬, 𝐭 𝐟(𝐱 − 𝐬, 𝐲 − 𝐭)
𝐬=−𝐚 𝐭=−𝐛

63
To obtain the value
at this position, place
the mask center here
=> result = 7*1=7

Same order as the


mask, consider an
impulse !

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

65
Spatial Smoothing Linear Filters

 The general implementation for filtering an MxN image


with a weighted average filter of size mxn is given
𝐚 𝐛
𝐬=−𝐚 𝐭=−𝐛 𝐰 𝐬, 𝐭 𝐟(𝐱 + 𝐬, 𝐲 + 𝐭)
𝐠 𝐱, 𝐲 = 𝐚 𝐛
𝐬=−𝐚 𝐭=−𝐛 𝐰 𝐬, 𝐭
Where m = 2a+1, n = 2b+1

66
Two Smoothing Averaging Filter
Masks

67
68
Example: Gross Representation of
Objects

69
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

70
Example: Use of Median
Filtering for Noise Reduction

71
Sharpening Spatial Filters

 Foundation
 Laplacian Operator
 Unsharp Masking and Highboost Filtering
 Using First-Order Derivatives for Nonlinear Image
Sharpening — The Gradient

72
Sharpening Spatial Filters:
Foundation
 The first-order derivative of a one-dimensional function
f(x) is the difference
𝛛𝐟
= 𝐟 𝐱 + 𝟏 − 𝐟(𝐱)
𝛛𝐱
 The second-order derivative of f(x) as the difference
𝛛𝟐 𝐟
𝟐
= 𝐟 𝐱 + 𝟏 + 𝐟 𝐱 − 𝟏 − 𝟐𝐟(𝐱)
𝛛𝐱

73
74
Sharpening Spatial Filters:
Laplace Operator
 The second-order isotropic derivative operator is the
Laplacian for a function (image) f(x,y):
𝛛𝟐𝐟 𝛛𝟐𝐟
𝛁𝟐 𝐟 = 𝟐 + 𝟐
𝛛𝐱 𝛛𝐲
𝛛𝟐 𝐟
𝟐
= 𝐟 𝐱 + 𝟏, 𝐲 + 𝐟 𝐱 − 𝟏, 𝐲 − 𝟐𝐟 𝐱, 𝐲
𝛛𝐱
𝛛𝟐 𝐟
𝟐
= 𝐟 𝐱, 𝐲 + 𝟏 + 𝐟 𝐱, 𝐲 − 𝟏 − 𝟐𝐟(𝐱, 𝐲)
𝛛𝐲
𝛁𝟐 𝐟 = 𝐟 𝐱 + 𝟏, 𝐲 + 𝐟 𝐱 − 𝟏, 𝐲 + 𝐟 𝐱, 𝐲 + 𝟏 + 𝐟 𝐱, 𝐲 − 𝟏 − 𝟒𝐟 𝐱, 𝐲

75
Sharpening Spatial Filters: Laplace Operator

76
Sharpening Spatial Filters:
Laplace Operator
 Image sharpening in the way of using the Laplacian:
𝐠 𝐱, 𝐲 = 𝐟 𝐱, 𝐲 + 𝐜 𝛁𝟐 𝐟(𝐱, 𝐲)
where
f(x,y) is input image
g(x,y) is sharpened image
c = -1 if 𝛁𝟐 𝐟(𝐱, 𝐲) corresponding to Fig. 3.37 (a) or (b)
and c = 1 if either of the other two filters is used.

77
78
Unsharp Masking and
Highboost Filtering
 Unsharp masking
Sharpening 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 (from step 2) to the original

79
Unsharp Masking and
Highboost Filtering

 Let 𝐟 𝐱, 𝐲 denote the blurred image, unsharp masking is


𝐠 𝐦𝐚𝐬𝐤 𝐱, 𝐲 = 𝐟 𝐱, 𝐲 − 𝐟 𝐱, 𝐲
Then add a weighted portion of the mask back to the
original
𝐠 𝐱, 𝐲 = 𝐟 𝐱, 𝐲 + 𝐤. 𝐠 𝐦𝐚𝐬𝐤 𝐱, 𝐲 𝐤≥𝟎
When k > 1, the process is referred to as highboost filtering

80
Unsharp Masking: Demo

81
Unsharp Masking and Highboost Filtering: Example

82
Image Sharpening based on
First-Order Derivatives
 For function f(x,y) the gradient of f at coordinates (x,y) is
defined as

𝛛𝐟
𝐠𝐱 𝛛𝐱
𝛁𝐟 ≡ 𝐠𝐫𝐚𝐝 𝐟 ≡ 𝐠 = 𝛛𝐟
𝐲
𝛛𝐲

 The magnitude of vector 𝛁𝐟 is denoted as M(x,y)

𝐌 𝐱, 𝐲 = 𝐦𝐚𝐠 𝛁𝐟 = 𝐠 𝐱𝟐 + 𝐠 𝐲𝟐

Gradient Image
83
Image Sharpening based on First-
Order Derivatives
 The magnitude of vector 𝛁𝐟 is denoted as M(x,y)

𝐌 𝐱, 𝐲 = 𝐦𝐚𝐠 𝛁𝐟 = 𝐠 𝐱𝟐 + 𝐠 𝐲𝟐

𝐌 𝐱, 𝐲 ≈ 𝐠 𝐱 + 𝐠 𝐲
𝐌 𝐱, 𝐲 ≈ 𝐳𝟖 − 𝐳𝟓 + 𝐳𝟔 − 𝐳𝟓

z1 z 2 z 3
z4 z 5 z 6
z7 z 8 z 9
84
Image Sharpening based on First-
Order Derivatives

 Roberts Cross-gradient Operators


𝐌 𝐱, 𝐲 ≈ 𝐳𝟗 − 𝐳𝟓 + 𝐳𝟖 − 𝐳𝟔
z1 z2 z3
 Sobel Operators
z4 z5 z6
𝐌 𝐱, 𝐲
z7 z8 z9 ≈ 𝐳𝟕 + 𝟐𝐳𝟖 + 𝒛𝟗 − (𝐳𝟏 + 𝟐𝐳𝟐 + 𝒛𝟑 )
+ 𝐳𝟑 + 𝟐𝐳𝟔 + 𝒛𝟗 − (𝐳𝟏 + 𝟐𝐳𝟒 + 𝒛𝟕 )

85
Image Sharpening based on First-
Order Derivatives

86
Example

87
Example:

Combining
Spatial
Enhancement
Methods

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

88
Example:

Combining
Spatial
Enhancement
Methods

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

89

You might also like