Professional Documents
Culture Documents
Intensity Transformation
and Spatial Filtering
10/22/20 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)
10/22/20 3
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)
► Works in the neighbourhood of every pixel
10/22/20 4
Spatial Domain Process
► Two principal image processing technique
classifications in spatial domain
Intensity transformation methods
►Operate on single pixels
Spatial filtering methods
►Works in the neighbourhood of every pixel
►Generally N X N where N > 1
10/22/20 6
10/22/20 7
Spatial Domain Process
10/22/20 8
Some Basic Intensity Transformation
Functions
10/22/20 9
Image Negatives
Image negatives
s L 1 r
10/22/20 10
Example: Image Negatives
Small
lesion
10/22/20 11
Log Transformations
Log Transformations
s c log(1 r )
10/22/20 12
Example: Log Transformations
10/22/20 13
Power-Law (Gamma) Transformations
s cr
10/22/20 14
Example: Gamma Transformations
10/22/20 15
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
sr 1/2.5
10/22/20 16
Example: Gamma Transformations
10/22/20 17
Example: Gamma Transformations
10/22/20 18
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.
10/22/20 19
10/22/20 20
Highlight the major
blood vessels and
study the shape of the
flow of the contrast
medium (to detect
blockages, etc.)
10/22/20 22
Bit-plane Slicing
10/22/20 23
Bit-plane Slicing
10/22/20 24
Histogram Processing
► Histogram Equalization
► Histogram Matching
10/22/20 25
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
10/22/20 26
10/22/20 27
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.
10/22/20 28
Histogram Equalization
s T (r ) 0 r L 1
10/22/20 29
Histogram Equalization
s T (r ) 0 r L 1
ps ( s)ds pr (r )dr
10/22/20 30
Histogram Equalization
r
s T (r ) ( L 1) pr ( w)dw
0
ds dT (r ) d r
dr
dr
( L 1)
dr 0
pr ( w) dw
( L 1) pr ( r )
pr (r )dr pr (r ) pr (r ) 1
ps ( s )
ds ds ( L 1) pr (r ) L 1
dr
10/22/20 31
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
10/22/20 32
Example
r
s T (r ) ( L 1) pr ( w)dw
0
r 2w
( L 1) dw
0 ( L 1) 2
2
r
L 1
10/22/20 33
Histogram Equalization
Continuous case:
r
s T (r ) ( L 1) pr ( w)dw
0
Discrete values:
k
sk T (rk ) ( L 1) pr (r j )
j 0
k nj L 1 k
( L 1) nj k=0,1,..., L-1
j 0 MN MN j 0
10/22/20 34
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.
10/22/20 35
Example: Histogram Equalization
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
10/22/20 36
Example: Histogram Equalization
10/22/20 37
10/22/20 38
10/22/20 39
Figure 3.22
(a) Image from Phoenix Lander. (b) Result of histogram
equalization. (c) Histogram of image (a). (d) Histogram of image
(b). (Original image courtesy of NASA.)
Question
Is histogram equalization always good?
No
10/22/20 41
Histogram Specification(Matching)
►Histogram equalization does not always provide
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Histogram equalization
Histogram Specification (cont...)
Histogram specification (cont.)
►In these cases, it is more useful to specify
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
r
s T (r ) ( L 1) pr ( w) dw
0
G ( z ) T (r )
►Equalize the target histogram: r
s G ( z ) ( L 1) pz ( w) dw
0
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
10/22/20 46
Histogram Matching: Example
10/22/20 49
► Obtain the scaled histogram-equalized values,
0
s0 T (r0 ) 7 pr (rj ) 7 pr (r0 ) 1.33
j 0
1
s1 T (r1 ) 7 pr (rj ) 7 pr (r0 ) 7 pr (r1 ) 3.08
j 0
► Rounding to the nearest integer:
s0 1.33 1 s1 3.08 3 s2 4.55 5 s3 5.67 6
s4 6.23 6 s5 6.65 7 s6 6.86 7 s7 7.00 7
Histogram Specification (cont...)
Example
10/22/20 55
Histogram Specification (cont...)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Histogram equalization
Histogram Specification (cont...)
Histogram Specification (cont...)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Specified histogram
Transformation function
and its inverse
Resulting histogram
10/22/20 59
10/22/20 60
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
10/22/20 61
Local Histogram Processing: Example
10/22/20 62
Using Histogram Statistics for Image
Enhancement
Average Intensity L 1 M 1 N 1
1
m ri p (ri )
MN
f ( x, y )
x 0 y 0
i 0
L 1
un (r ) (ri m) n p (ri )
i 0
Variance L 1 M 1 N 1
1
u2 (r ) (ri m) p (ri ) f ( x, y ) m
2 2 2
i 0
MN x 0 y 0
10/22/20 63
Using Histogram Statistics for Image
Enhancement
Local variance
L 1
2
s xy (ri msxy ) psxy (ri )
2
i 0
10/22/20 64
Using Histogram Statistics for Image
Enhancement: Example
10/22/20 65
Figure 3.33
(a) Original image. (b) Result of local enhancement based on
local histogram statistics. Compare (b) with Fig. 3.32(c).
Spatial Filtering
a b
g ( x, y ) w(s, t ) f ( x s, y t )
s a t b
10/22/20 67
Spatial Filtering
10/22/20 68
Spatial Correlation
a b
w( x, y ) f ( x, y ) w(s, t ) f ( x s, y t )
s a t b
10/22/20 69
Spatial Convolution
a b
w( x, y ) f ( x, y ) w(s, t ) f ( x s, y t )
s a t b
10/22/20 70
Figure 3.35
Illustration of 1-D correlation and convolution of a kernel, w, with a function f consisting of a
discrete unit impulse. Note that correlation and convolution are functions of the variable x, which
acts to displace one function with respect to the other. For the extended correlation and
convolution results, the starting configuration places the rightmost element of the kernel to be
coincident with the origin of f. Additional padding must be used.
10/22/20 72
10/22/20 73
Figure 3.58
Transfer functions of ideal 1-D filters in the frequency domain (u
denotes frequency). (a) Lowpass filter. (b) Highpass filter. (c)
Bandreject filter. (d) Bandpass filter. (As before, we show only
positive frequencies for simplicity.)
Table 3.7
Summary of the four principal spatial filter types expressed in
terms of lowpass filters. The centers of the unit impulse and the
filter kernels coincide.
Smoothing Spatial Filters
10/22/20 76
Spatial Smoothing Linear Filters
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.
10/22/20 77
Two Smoothing Averaging Filter Masks
10/22/20 78
10/22/20 79
Example: Gross Representation of Objects
10/22/20 80
Order-statistic (Nonlinear) Filters
— Nonlinear
10/22/20 81
Example: Use of Median Filtering for Noise Reduction
10/22/20 82
Sharpening Spatial Filters
► Foundation
► Laplacian Operator
10/22/20 83
Sharpening Spatial Filters: Foundation
f
f ( x 1) f ( x)
x
2 f
f ( x 1) f ( x 1) 2 f ( x)
x 2
10/22/20 84
10/22/20 85
Sharpening Spatial Filters: Laplace Operator
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 )
10/22/20 86
Sharpening Spatial Filters: Laplace Operator
10/22/20 87
Sharpening Spatial Filters: Laplace Operator
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.
10/22/20 88
10/22/20 89
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
10/22/20 90
Unsharp Masking and Highboost Filtering
10/22/20 91
Unsharp Masking: Demo
10/22/20 92
Figure 3.55
(c) Mask. (d) Result of unsharp masking using Eq. (3-65) with k = 1. (e) and (f)
Results of highboost filtering with k = 2 and k = 3, respectively.
Unsharp Masking and Highboost Filtering: Example
10/22/20 94
Image Sharpening based on First-Order Derivatives
M ( x, y ) | g x | | g y |
z1 z2 z3
M ( x, y ) | z8 z5 | | z6 z5 |
z4 z5 z6
z7 z8 z9
10/22/20 96
Image Sharpening based on First-Order Derivatives
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
10/22/20 97
Image Sharpening based on First-Order Derivatives
10/22/20 98
Example
10/22/20 99
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail
10/22/20 100
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail
10/22/20 101