Uploaded by Dr. Syed Md. Galib

ImageProcessing-g&w3e-chap3

advertisement
Lecture 2. Intensity Transformation
and Spatial Filtering
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
1/9/2024
2
Spatial Domain Process
g ( x, y )  T [ f ( x, y )])
f ( x, y ) : input image
g ( x, y ) : output image
T : an operator on f defined over
a neighborhood of point ( x, y)
1/9/2024
3
Spatial Domain Process
1/9/2024
4
Spatial Domain Process
Intensity transformation function
s  T (r )
1/9/2024
5
Some Basic Intensity Transformation
Functions
1/9/2024
6
Image Negatives
Image negatives
s  L 1 r
1/9/2024
7
Example: Image Negatives
Small
lesion
1/9/2024
8
Log Transformations
Log Transformations
s  c log(1  r )
1/9/2024
9
Example: Log Transformations
1/9/2024
10
Power-Law (Gamma) Transformations
s  cr
1/9/2024

11
Example: Gamma Transformations
1/9/2024
12
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
sr
1/9/2024
1/2.5
13
Example: Gamma Transformations
1/9/2024
14
Example: Gamma Transformations
1/9/2024
15
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.
1/9/2024
16
1/9/2024
17
Highlight the major
blood vessels and
study the shape of the
flow of the contrast
medium (to detect
blockages, etc.)
1/9/2024
Measuring the actual
flow of the contrast
medium as a function
of time in a series of
images
18
Bit-plane Slicing
1/9/2024
19
Bit-plane Slicing
1/9/2024
20
Bit-plane Slicing
1/9/2024
21
Histogram Processing
►
Histogram Equalization
►
Histogram Matching
►
Local Histogram Processing
►
Using Histogram Statistics for Image Enhancement
1/9/2024
22
Histogram Processing
Histogram h( rk )  nk
rk is the k th intensity value
nk is the number of pixels in the image with intensity rk
nk
Normalized histogram p (rk ) 
MN
nk : the number of pixels in the image of
size M  N with intensity rk
1/9/2024
23
1/9/2024
24
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.
1/9/2024
25
Histogram Equalization
s  T (r )
0  r  L 1
a. T(r) is a strictly monotonically increasing function
in the interval 0  r  L -1;
b. 0  T (r )  L -1 for 0  r  L -1.
1/9/2024
26
Histogram Equalization
s  T (r )
0  r  L 1
a. T(r) is a strictly monotonically increasing function
in the interval 0  r  L -1;
b. 0  T (r )  L -1 for 0  r  L -1.
T (r ) is continuous and differentiable.
ps (s)ds  pr (r )dr
1/9/2024
27
Histogram Equalization
r
s  T (r )  ( L  1)  pr ( w)dw
0
ds dT (r )
d  r


 ( L  1)
p
(
w
)
dw
r



0
dr
dr
dr 
 ( L  1) pr (r )
pr (r )dr pr (r )
1
pr (r )
ps ( s) 



 ( L  1) pr (r )  L  1
 ds 
ds
 
 dr 
1/9/2024
28
Example
Suppose that the (continuous) intensity values
in an image have the PDF
 2r
,

2
pr (r )   ( L  1)
 0,

for 0  r  L-1
otherwise
Find the transformation function for equalizing
the image histogram.
1/9/2024
29
Example
r
s  T (r )  ( L  1)  pr ( w)dw
0
 ( L  1) 
r
0
2w
dw
2
( L  1)
2
r

L 1
1/9/2024
30
Histogram Equalization
Continuous case:
r
s  T (r )  ( L  1)  pr ( w)dw
0
Discrete values:
k
sk  T (rk )  ( L  1) pr (rj )
j 0
L 1 k
 ( L  1)

nj

MN j 0
j  0 MN
k
1/9/2024
nj
k=0,1,..., L-1
31
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.
1/9/2024
32
Example: Histogram Equalization
0
s0  T (r0 )  7 pr (rj )  7  0.19  1.33
1
s1  T (r1 )  7 pr (rj )  7  (0.19  0.25)  3.08
3
j 0
1
j 0
1/9/2024
s2  4.55  5
s3  5.67  6
s4  6.23  6
s5  6.65  7
s6  6.86  7
s7  7.00  7
33
Example: Histogram Equalization
1/9/2024
34
1/9/2024
35
1/9/2024
36
Question
Is histogram equalization always good?
No
1/9/2024
37
Histogram Matching
Histogram matching (histogram specification)
— generate a processed image that has a specified histogram
Let pr ( r ) and pz ( z ) denote the continous 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
r
s  T ( r )  ( L  1)  pr ( w) dw
0
Define a random variable z with the probability
z
G ( z )  ( L  1)  pz (t ) dt  s
0
1/9/2024
38
Histogram Matching
r
s  T (r )  ( L  1)  pr ( w)dw
0
z
G ( z )  ( L  1)  pz (t )dt  s
0
1
z  G (s)  G
1/9/2024
1
T (r )
39
Histogram Matching: Procedure
►
Obtain pr(r) from the input image and then obtain the values of s
r
s  ( L  1)  pr ( w)dw
0
►
Use the specified PDF and obtain the transformation function G(z)
z
G ( z )  ( L  1)  pz (t )dt  s
0
►
Mapping from s to z
z  G 1 (s)
1/9/2024
40
Histogram Matching: Example
Assuming continuous intensity values, suppose that an image has
the intensity PDF
 2r
,

2
pr (r )   ( L  1)
 0,

for 0  r  L -1
otherwise
Find the transformation function that will produce an image
whose intensity PDF is
 3z 2
,

3
pz ( z )   ( L  1)
 0,

1/9/2024
for 0  z  ( L -1)
otherwise
41
Histogram Matching: Example
Find the histogram equalization transformation for the input image
r
r
0
0
s  T (r )  ( L  1)  pr ( w)dw  ( L  1) 
2
r
2w
dw 
2
( L  1)
L 1
Find the histogram equalization transformation for the specified histogram
z
z
0
0
G ( z )  ( L  1)  pz (t )dt  ( L  1) 
3t 2
z3
dt 
s
3
2
( L  1)
( L  1)
The transformation function
1/3
z  ( L  1) s 
2
1/9/2024
1/3


2 r
 ( L  1)

L

1


2
2 1/3
 ( L  1)r 
42
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].
( L  1) k
sk  T (rk )  ( L  1) pr (rj ) 
nj

MN j 0
j 0
k
►
Use the specified PDF and obtain the transformation function
G(zq), round the value to the integer range [0, L-1].
q
G ( zq )  ( L  1) pz ( zi )  sk
i 0
►
Mapping from sk to zq
1/9/2024
zq  G 1 ( sk )
43
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.
1/9/2024
44
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 ( z3 )  1.05
1
G ( z7 )  7.00
7
G ( z5 )  4.55  5
1/9/2024
G ( z2 )  0.00  0
G ( z4 )  2.45  2
G ( z6 )  5.95  6
45
Example: Histogram Matching
1/9/2024
46
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
G ( z3 )  1.05
0
 1 s0
G ( z5 )  4.55  5
G ( z7 )  7.00
1/9/2024
7
s2
s4
G ( z2 )  0.00  0
G ( z4 )  2.45  2 s1
G ( z6 )  5.95  6 s3
s5 s6 s7
47
Example: Histogram Matching
s0  1, s1  3, s2  5, s3  6, s4  7,
s5  7, s6  7, s7  7.
rk
0
1
2
3
4
5
1/9/2024
6
7
48
Example: Histogram Matching
rk  zq
03
1 4
25
36
47
57
67
77
1/9/2024
49
Example: Histogram Matching
1/9/2024
50
Example: Histogram Matching
1/9/2024
51
Example: Histogram Matching
1/9/2024
52
Example: Histogram Matching
1/9/2024
53
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
1/9/2024
54
Local Histogram Processing: Example
1/9/2024
55
Using Histogram Statistics for Image
Enhancement
Average Intensity
L 1
m   ri p (ri )
i 0
1

MN
M 1 N 1
  f ( x, y )
x 0 y 0
L 1
un (r )   (ri  m) n p (ri )
i 0
Variance
L 1
  u2 (r )   (ri
2
i 0
1/9/2024
1
2

 m) p (ri )
MN
M 1 N 1
   f ( x, y )  m 
2
x 0 y 0
56
Using Histogram Statistics for Image
Enhancement
Local average intensity
L 1
msxy   ri psxy (ri )
i 0
sxy denotes a neighborhood
Local variance

1/9/2024
L 1
2
s xy
  (ri  msxy ) psxy (ri )
2
i 0
57
Using Histogram Statistics for Image
Enhancement: Example
 E f ( x, y ), if msxy  k0 mG and k1 G   sxy  k2 G
g ( x, y )  
otherwise
 f ( x, y ),
mG : global mean;
 G : global standard deviation
k0  0.4; k1  0.02; k2  0.4; E  4
1/9/2024
58
Spatial Filtering
A spatial filter consists of (a) a neighborhood, and (b) a
predefined operation
Linear spatial filtering of an image of size MxN with a filter
of size mxn is given by the expression
g ( x, y ) 
a
b
  w(s, t ) f ( x  s, y  t )
s  a t  b
1/9/2024
59
Spatial Filtering
1/9/2024
60
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 )
w( x, y )
f ( x, y ) 
a
b
  w(s, t ) f ( x  s, y  t )
s  a t  b
1/9/2024
61
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 )
w( x, y )
f ( x, y ) 
a
b
  w(s, t ) f ( x  s, y  t )
s  a t  b
1/9/2024
62
1/9/2024
63
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.
1/9/2024
64
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
g ( x, y ) 
b
  w(s, t ) f ( x  s, y  t )
s  a t  b
a
b
  w(s, t )
s  a t  b
where m  2a  1,
1/9/2024
n  2b  1.
65
Two Smoothing Averaging Filter Masks
1/9/2024
66
1/9/2024
67
Example: Gross Representation of Objects
1/9/2024
68
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
1/9/2024
69
Example: Use of Median Filtering for Noise Reduction
1/9/2024
70
Sharpening Spatial Filters
►
Foundation
►
Laplacian Operator
►
Unsharp Masking and Highboost Filtering
►
1/9/2024
Using First-Order Derivatives for Nonlinear Image
Sharpening — The Gradient
71
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)
2
x
1/9/2024
72
1/9/2024
73
Sharpening Spatial Filters: Laplace Operator
The second-order isotropic derivative operator is the
Laplacian for a function (image) f(x,y)
2
2

f

f
2
 f  2  2
x
y
2 f
 f ( x  1, y )  f ( x  1, y )  2 f ( x, y )
2
x
2 f
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y )
2
y
 2 f  f ( x  1, y )  f ( x  1, y )  f ( x, y  1)  f ( x, y  1)
- 4 f ( x, y )
1/9/2024
74
Sharpening Spatial Filters: Laplace Operator
1/9/2024
75
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.
1/9/2024
76
1/9/2024
77
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
1/9/2024
78
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.
1/9/2024
79
Unsharp Masking: Demo
1/9/2024
80
Unsharp Masking and Highboost Filtering: Example
1/9/2024
81
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
1/9/2024
M ( x, y )  mag(f )  g x 2  g y 2
82
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
z4
z7
1/9/2024
z2
z5
z8
z3
z6
z9
M ( x, y) | z8  z5 |  | z6  z5 |
83
Image Sharpening based on First-Order Derivatives
Roberts Cross-gradient Operators
M ( x, y ) | z9  z5 |  | z8  z6 |
Sobel Operators
z1
z4
z7
1/9/2024
z2
z5
z8
z3
z6
z9
M ( x, y ) | ( z7  2 z8  z9 )  ( z1  2 z2  z3 ) |
 | ( z3  2 z6  z9 )  ( z1  2 z4  z7 ) |
84
Image Sharpening based on First-Order Derivatives
1/9/2024
85
Example
1/9/2024
86
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail
1/9/2024
87
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail
1/9/2024
88
Download