3. TJ Cham
2011/12 S1
Two classes of processing in the
spatial domain
• Point Processing
– Each pixel’s new gray-level does
not depend on other pixel’s gray-
level
• Spatial Filtering
– Each pixel’s new gray-level
depends on current gray-level of
neighbouring pixels
SCSE CE7491 Digital Image Processing
3
4. TJ Cham
2011/12 S1
Point Processing
• Pixel gray-level transformation expressed as a function
• Some transformations may be dependent on global
statistics, e.g.
– Maximum and minimum pixel gray-levels present in
the image
– Histogram of pixel gray-levels
)
(r
T
s =
SCSE CE7491 Digital Image Processing
4
5. TJ Cham
2011/12 S1
Pixel Intensity Transformation
Original gray-levels
New
gray-levels
0 255
0
255
r
s
SCSE CE7491 Digital Image Processing
5
6. TJ Cham
2011/12 S1
6
SCSE CE7491 Digital Image Processing
Image Negatives
• Inverting gray-levels produced equivalent
of photographic negatives
• For image with gray-levels in the range [0,
L-1], transformation is
0 255
0
255
r
s
r
L
s −
−
= 1
7. TJ Cham
2011/12 S1
7
SCSE CE7491 Digital Image Processing
Contrast Stretching
• Increase contrast of images captured under poor illumination, wrong
camera setting, etc.
– Maximizes dynamic range
• rmax = max gray-level present
in image
• rmin = min gray-level present
in image 0 255
0
255
r
s
−
−
=
max
max
min
min
max
min
min
255
255
0
r
r
r
r
r
r
r
r
r
r
r
s
rmax
rmin
8. TJ Cham
2011/12 S1
8
SCSE CE7491 Digital Image Processing
Contrast Stretching
• Min present gray-level ➔ 0
• Max present gray-level ➔ 255
• Linear scale in-between
9. TJ Cham
2011/12 S1
9
SCSE CE7491 Digital Image Processing
Gray-Level Histograms of Images
• A gray-level histogram of an image
shows how frequently different gray-
levels appear in the image
• Can be represented as bin counts, or
probability distributions if divided by
total number of pixels in the image
• Example:
Pixel gray levels
Frequency
/
probability
10. TJ Cham
2011/12 S1
10
SCSE CE7491 Digital Image Processing
Histogram Equalization
• Histogram equalization attempts to flatten the gray-level histogram
through a gray-level transformation
• Q: What is this gray-level transformation?
Pixel gray levels
Frequency
/
probability
Pixel gray levels
Frequency
/
probability
?
11. TJ Cham
2011/12 S1
11
SCSE CE7491 Digital Image Processing
Histogram Equalization
• Can be used improve contrast of details in images containing very
light and dark regions
• E.g.
12. TJ Cham
2011/12 S1
12
SCSE CE7491 Digital Image Processing
Histogram Equalization
• Consider pixel gray-levels normalized to [0,1],
i.e. 0 ≤ r ≤ 1, 0 ≤ s ≤ 1
• The transformation s = T(r) for histogram equalization must satisfy the
following:
– T(r) is single-valued and monotonically increasing in the
interval 0 ≤ r ≤ 1
– 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1
• In continuous domain, histogram equalized by:
– Transformation same as cumulative
distribution function for gray-levels!
=
=
r
r d
p
r
T
s
0
)
(
)
(
14. TJ Cham
2011/12 S1
Histogram Equalization
r
r
s
s
pr(r)
ps(s)
=
r
r dr
r
p
s )
(
dr
r
p
ds r )
(
1 =
1
SCSE CE7491 Digital Image Processing
14
15. TJ Cham
2011/12 S1
15
SCSE CE7491 Digital Image Processing
Histogram Equalization
• Note derivation is only for
continuous gray-levels
• Need to adapt to discrete gray
levels in digital images
– Cumulative sum of histogram
bins
• See recommended text and
Matlab help for details of
discrete algorithms
16. TJ Cham
2011/12 S1
16
SCSE CE7491 Digital Image Processing
Arithmetic / Logic Operations
• An image is also an array of numbers
• We can carry out arithmetic and logic operations with
other images, e.g.
– Image masking
– Image subtraction
– Image averaging
17. TJ Cham
2011/12 S1
17
SCSE CE7491 Digital Image Processing
Image Masking
• Regions of interest in an image can be selected by AND
or OR operations with image masks, e.g.
)
,
(
&
)
,
(
)
,
( y
x
m
y
x
f
y
x
g =
18. TJ Cham
2011/12 S1
18
SCSE CE7491 Digital Image Processing
Image Subtraction
• Image subtraction can be used to detect changes from
one image to the next
)
,
(
)
,
(
)
,
( y
x
h
y
x
f
y
x
g −
=
19. TJ Cham
2011/12 S1
19
SCSE CE7491 Digital Image Processing
Image Averaging
• For series of static images, image
averaging can be used to suppress
additive noise
• Best performance under i.i.d. zero-
mean assumptions
– f(x,y) is the ideal but unknown
image
– η is an additive zero-mean,
uncorrelated noise
+
= )
,
(
)
,
( y
x
f
y
x
g
20. TJ Cham
2011/12 S1
20
SCSE CE7491 Digital Image Processing
Spatial Filtering
• Spatial filtering computes each pixel new gray-level based on the
existing gray-levels of neighboring pixels
• Linear spatial filtering involves convolving a normal (large) image
with a small image known as a filter, mask, kernel, template or
window
21. TJ Cham
2011/12 S1
21
SCSE CE7491 Digital Image Processing
Discrete 2D Convolution
• Images are finite – assume pixel values to be zero outside image
boundaries
• Consider a filter h(x,y)
– size: width = 2a+1, height = 2b+1
– usually treat centre pixel as origin (0,0)
• Discrete 2D convolution expressed as
−
= −
=
−
= −
=
−
−
+
+
=
−
−
=
a
a
u
b
b
v
a
a
u
b
b
v
v
u
h
v
y
u
x
f
v
u
h
v
y
u
x
f
y
x
g
)
,
(
)
,
(
)
,
(
)
,
(
)
,
(
22. TJ Cham
2011/12 S1
22
SCSE CE7491 Digital Image Processing
2D Spatial Filtering Steps
• To compute output value at a specific pixel location
(x’,y’):
1. Rotate filter h(u,v) 180° around to get h(-u,-v)
2. Overlay filter centre pixel at input image location
(x’,y’)
3. Multiply overlapping image and filter pixels, and sum
4. Put sum in output image (x’,y’) location.
24. TJ Cham
2011/12 S1
24
SCSE CE7491 Digital Image Processing
Impulse Response and Point-Spread
Function
• The filter h(x,y) may also be considered as the impulse response of
the filter system
• With an impulse input (i.e. f = )
• Sometimes, h(x,y) is also known as the Point-Spread Function
(PSF), since an input impulse becomes ‘spread out’
)
,
(
)
,
(
)
,
(
)
,
(
y
x
h
v
u
h
v
y
u
x
y
x
g
a
a
u
b
b
v
=
−
−
=
−
= −
=
25. TJ Cham
2011/12 S1
25
SCSE CE7491 Digital Image Processing
Averaging Filter
• Also known as a box filter
• Different filter sizes may also be
used
1 1 1
1 1 1
1 1 1
1
9
×
26. TJ Cham
2011/12 S1
26
SCSE CE7491 Digital Image Processing
Gaussian Smoothing
• Gaussian smoothing filters have the shape of a 2D uniform variate
Normal density function
• Compute at discrete values for different size spatial filters, and
normalize sum of filter coefficients to 1
– E.g. 3x3 filter
2
2
2
2
2
2
1
)
,
(
y
x
e
y
x
h
+
−
=
0.075114 0.123841 0.075114
0.123841 0.20418 0.123841
0.075114 0.123841 0.075114
27. TJ Cham
2011/12 S1
27
SCSE CE7491 Digital Image Processing
Sharpening Linear Filters
• Averaging ≈ integration ➔ image blurring
• Therefore, differentiation ➔ image sharpening
• Applying filters that enhance image derivatives will
sharpen images
28. TJ Cham
2011/12 S1
28
SCSE CE7491 Digital Image Processing
Laplacian Filter
• The Laplacian of a 2D function f is defined
by
• A discrete approximation of the operator is
represented by the filter
2
2
2
2
2
y
f
x
f
f
+
=
1 1 1
1 -8 1
1 1 1
29. TJ Cham
2011/12 S1
29
SCSE CE7491 Digital Image Processing
High Boost Filtering
• Laplacian filter enhances edges only
– eliminates slowly varying image regions – may not be desirable
• High boost filtering
– mix original image f(x,y) and Laplacian filtered image fs(x,y)
1
),
,
(
)
,
(
)
1
(
)
,
(
+
−
= A
y
x
f
y
x
f
A
y
x
f s
hb
30. TJ Cham
2011/12 S1
30
SCSE CE7491 Digital Image Processing
Nonlinear Filtering : Order Statistics
• In order statistics filtering:
1. neighborhood input pixels are ranked by their gray-levels
2. Output pixel is the nth-ranked pixel gray-level
• e.g. median filter
3 0 5
10 21 14
17 6 0
21
17
14
10
6
5
3
0
0
31. TJ Cham
2011/12 S1
31
SCSE CE7491 Digital Image Processing
Median Filtering
• Median filter is a 50 percentile order statistics filter
• Useful for removing impulse noise, also known as speckle or salt-
and-pepper noise