Upload
others
View
9
Download
1
Embed Size (px)
Citation preview
Image Enhancement in the
Spatial Domain
Raul Queiroz Feitosa
8/21/2019 Enhancement in the Spatial Domain 2
Enhancement in the Spatial
Domain Contents
Introduction
Background
Point Processing
Histogram Processing
Local Enhancement
Spatial Filters
Smoothing Filters
Sharpening Filters
8/21/2019 Enhancement in the Spatial Domain 3
Introduction
Two Groups of Enhancement Techniques :
In the Spatial Domain
Based on the direct manipulation of the pixels in an image.
In the Frequency Domain
Based on modifying the Fourier Transform of an image.
pre-
processing
segmen-
tation
feature
extraction
feature
selection
classifi-
cation
post-
processing data label
8/21/2019 Enhancement in the Spatial Domain 4
Background
Notation
g(x,y) =T [ f(x,y) ] where
f(x,y) is the input image,
g(x,y) is the output image, and
T is an operator defined over a neighborhood of (x,y).
x
y
(x,y)
8/21/2019 Enhancement in the Spatial Domain 5
Background
Two groups of approaches:
Point Processing: when the neighborhood is of size
1×1, it becomes a gray level (or intensity or mapping)
transformation function of the form:
s =T (r)
where r and s denote the gray level at f(x,y) and g(x,y)
at any point g(x,y) .
Larger neighborhoods: it bases on the use of small
arrays called mask, whose coefficients determine the
nature of the process.
8/21/2019 Enhancement in the Spatial Domain 6
Point Processing
Image Negatives
Ou
tpu
t g
ray
leve
l -
s
Input gray level - r
T(r)
8/21/2019 Enhancement in the Spatial Domain 7
Point Processing
(r1,s1)
(r2,s2)
T(r)
Ou
tpu
t g
ray
leve
l -
s
Input gray level - r
Contrast Stretching
8/21/2019 Enhancement in the Spatial Domain 8
Point Processing
Power Law-Transformation
Correção Gama
Input gray level - r
maxmax/where, rsccrs
Ou
tpu
t g
ray
leve
l -
s
γ=0.04
γ=0.1
γ=0.2
γ=0.4
γ=0.67
γ=1
γ=1.5
γ=2.5
γ=5.0
γ=10
γ=25
8/21/2019 Enhancement in the Spatial Domain 9
Point Processing
Power Law-Transformation
γ=0.04
γ=0.1
γ=0.2
γ=0.4
γ=0.67
γ=1
γ=1.5
γ=2.5
γ=5.0
γ=10
γ=25
Correção Gama
Input gray level - r
maxmax/where, rsccrs
Ou
tpu
t g
ray
leve
l -
s
γ=0.04
γ=0.1
γ=0.2
γ=0.4
γ=0.67
γ=1
γ=1.5
γ=2.5
γ=5.0
γ=10
γ=25
8/21/2019 Enhancement in the Spatial Domain 10
Point Processing
Brightness Adjustment
10 tosubjected, sbrs
Input gray level - r
Ou
tpu
t g
ray
leve
l -
s
8/21/2019 Enhancement in the Spatial Domain 11
Histogram Processing
Definition
The histogram of a digital image with gray levels
in the range [0,L-1] is a discrete function
h (rk) = nk/n
where
rk is the kth gray level,
nk is the number of pixels having gray level rk, and
n is the number of pixels in the image.
8/21/2019 Enhancement in the Spatial Domain 12
Histogram Processing
Example: dark image
8/21/2019 Enhancement in the Spatial Domain 13
Histogram Processing
Example: bright image
8/21/2019 Enhancement in the Spatial Domain 14
Histogram Processing
Example: image with low contrast
8/21/2019 Enhancement in the Spatial Domain 15
Histogram Processing
Example: image with high contrast
8/21/2019 Enhancement in the Spatial Domain 16
Histogram Processing
Equalization
Problem formulation:
Design a function s =T (r) that transforms a given input
image so that the output image has uniformly
distributed gray levels.
8/21/2019 Enhancement in the Spatial Domain 17
Histogram Processing
Equalization
Solution:
Let pr(r) and ps(s) be the histogram of the input and of the output
images, respectively.
Assume that r and s represent continuous gray levels in the
interval [0,1].
Search for the transformation function T (r) satisfying the
following conditions:
a) T(r) is a single-valued and monotonically increasing in [0,1].
b) 0 ≤ T(r) ≤ 1, for 0 ≤ r≤ 1,
c) the inverse function T-1(s) must also meet the above conditions.
8/21/2019 Enhancement in the Spatial Domain 18
Histogram Processing
Equalization
In the continuous case
In the discrete case
for k = 0,1,…,L-1
r
rrdwwprTs
0
10)()(
j
k
j
r
k
j
j
kkrp
n
nrTs
00
sk
rk
8/21/2019 Enhancement in the Spatial Domain 19
Histogram Processing
Equalization: example
T(r)
r
Equalization
8/21/2019 Enhancement in the Spatial Domain 20
Histogram Processing Histogram Matching
Problem formulation:
Design a transformation function s =T (r) that transforms a given
input image so that the output image has a specified histogram.
Solution:
Let pr(r) and ps(s) be the histogram respectively of the input image and
the desired histogram. The function s =T (r) will be computed by:
r
rdwwprH
0
.)()( s
sdwwpsG
0
.)()(
.1rHGz
)(1
zG
pr(r) uniform ps(s)
Histogram Processing
Histogram Matching : example
8/21/2019 Enhancement in the Spatial Domain 21
Source: Matthew Perry
8/21/2019 Enhancement in the Spatial Domain 22
Local Enhancement
The parameters of most functions presented so far are
computed based on the whole image.
To enhance details in small image areas (example):
1. Select a neighborhood, whose center moves from pixel to pixel
over the image.
2. At each position find the transformation function based on the
pixel neighborhood.
3. Apply the function to the pixel at the center of the neighborhood.
4. Move the center to the next pixel and repeat steps 2 and 3 till all
image is covered.
8/21/2019 Enhancement in the Spatial Domain 23
Local Enhancement
Example: local histogram equalization
Original Image After Global Equalization After Local Equalization
8/21/2019 Enhancement in the Spatial Domain 24
Local Enhancement
Histogram Statistic for Enhancement
Global statistics: the nth moment about the mean
where
Local statistics: Let (x,y) be the pixel coordinates and Sxy a neighborhood with
a given size around (x,y). We define
the average gray level around Sxy
the contrast around Sxy
i
L
i
n
inrpmrr
1
0
1
0
L
i
iirprm
xy
xyxy
Sts
tsStsSrpmr
),(
,
2
,
2
xy
xy
Sts
tstsSrprm
,
,,
8/21/2019 Enhancement in the Spatial Domain 25
Local Enhancement Histogram Statistic for Enhancement (example)
f (x,y) / g (x,y) the input/output images,
MG and DG are the global mean and standard deviation respectively,
E, k0, k1 e k2, are specified parameters.
only dark, non uniform areas
with low contrast are modified
where, otherwise,,
AND if,,
210
yxf
DkDkMkmyxfEyxg
GSGGSxyxy
{E=4;k0=0.4;k1=0.02;k2=0.4}
8/21/2019 Enhancement in the Spatial Domain 26
Local Enhancement Histogram Statistic for Enhancement (example)
f (x,y) / g (x,y) the input/output images,
MG and DG are the global mean and standard deviation respectively,
E, k0, k1 e k2, are specified parameters;
only dark, non uniform areas with low contrast are modified
where , otherwise , ,
AND if , ,
2 1 0
y x f
D k D k M k m y x f E y x g
G S G G S xy xy
0 M k m G S xy
1 D k S G xy
2 D k G S xy
8/21/2019 Enhancement in the Spatial Domain 27
Region of Interest Processing
(ROI) • logical matrices called masks can be used to define regions in
an image (roi) where an operator is to be applied.
• Example: blurring uninteresting regions
input image mask (roi) output image
8/21/2019 Enhancement in the Spatial Domain 28
Spatial Filters
Operation: g(x,y)=T [ f(x,y)],
w1 w3 w2
w7 w9 w8
w4 w6 w5
Response of a linear spatial filter
R=w1z1+ w2z2+ . . .+ w9z9
w1
w1
w1
w1 w3 w2
w7 w9 w8
w4 w6 w5
w1
w1
w1
w1 w3 w2
w7 w9 w8
w4 w6 w5
w1
w1
w1
w1
w1
w1
w1 w3 w2
w7 w9 w8
w4 w6 w5
w1
w1
w1
w1
w1
w1
w1
w1
w1
w1 w3 w2
w7 w9 w8
w4 w6 w5
w1
w1
w1 . . .
w1 w1 w1
w1 w3 w2
w7 w9 w8
w4 w6 w5
w1 w1 w1 w1 w1 w1 w1
w1
w1
w1
w1 w3 w2
w7 w9 w8
w4 w6 w5
Image
a
as
b
bt
tysxftswyxg ,,,
8/21/2019 Enhancement in the Spatial Domain 29
Smoothing Filters
Aplications:
Removal of small details prior to large object extraction.
Noise reduction.
Side Effect
It blurs the image.
Smoothing masks
All elements are non-negative, and
sum up to 1.
Masks
1 1 1
1 1 1
1 1 1 1/9
averaging filter 3×3
1 1 7
1 1 7
7 7 54 1/88
gaussian filter 3×3
8/21/2019 Enhancement in the Spatial Domain 30
Smoothing Filters
Examples of applying an averaging filter :
original 3×3 5×5
7×7 15×15 25×25
8/21/2019 Enhancement in the Spatial Domain 31
Smoothing Filters
Order Statistic Filters
are non-linear spatial filters whose response is
based on ordering (ranking) the pixels contained
in the image area encompassed by the mask, and
then replacing the value of the center pixel with
the value determined by the ranking result.
8/21/2019 Enhancement in the Spatial Domain 32
Smoothing Filters
Order Statistic Filters:
Median Filter
replaces the value of a pixel by the median of the gray
levels in its neighborhood
A median ξ of a set of values is such that half of the
values in the set is lower than ξ and half of the values
in the set is greater than or equal to ξ .
Percentile Filter
replaces the value of a pixel by n-th percentile of the
gray levels in its neighborhood.
8/21/2019 Enhancement in the Spatial Domain 33
Smoothing Filters
Examples :
Original image Image with salt-and-pepper noise
After average 5x5 filtering After median filtering
8/21/2019 Enhancement in the Spatial Domain 34
Adaptive Filter
The output g(x,y) of a adaptive filter depends on
the statistical characteristics of the input image
f(x,y) inside a m×n rectangular window Sxy
centered at (x,y).
L
L
myxfyxfyxg ),(),(),(2
2
variance in Sxy mean in Sxy
variance of the noise (?)
8/21/2019 Enhancement in the Spatial Domain 35
Adaptive Filter
Example
image corrupted by
additive Gaussian
noise of zero mean
and variance 1000
result of an adaptive
noise reduction filter
result of an arithmetic
mean filter
8/21/2019 Enhancement in the Spatial Domain 36
Sharpening Filters
Applications
Highlight of fine details.
Enhance details that have been blurred due to the
acquisition method.
Side Effect
Emphasizes the noise.
8/21/2019 Enhancement in the Spatial Domain 37
Sharpening Filters
Accomplished by spatial differentiation:
Approximation for the 1ª derivative
Approximation for the 2ª derivative
xfxf
x
xfxxf
x
xf
ox
1lim
121
22
2
lim
xfxfxf
x
xxfxfxfxxf
x
xf
ox
8/21/2019 Enhancement in the Spatial Domain 38
Sharpening Filters
Illustration
8/21/2019 Enhancement in the Spatial Domain 39
Sharpening Filters
From the previous slide we may conclude:
1. First-order derivatives generally produce thicker
edges in the image,
2. Second-order derivatives have a stronger response at
the fine details,
3. First-order derivatives generally have a stronger
response to a gray-level step, and
4. Second-order derivatives have a double-response at
step changes in gray level.
8/21/2019 Enhancement in the Spatial Domain 40
Sharpening Filters
Laplacian Filter
Starting from
we obtain
2
2
2
2
2
y
f
x
ff
yxfyxfyxfyxfyxff ,41,1,,1,12
yxfyxfyxfx
f,1,2,1
2
2
1,,21,2
2
yxfyxfyxf
y
f
8/21/2019 Enhancement in the Spatial Domain 41
Sharpening Filters
Laplacian Filter: example of masks
0 1 0
0 1 0
1 -4 1
1 4 1
1 4 1
4 -20 4
1 1 1
1 1 1
1 -8 1
8/21/2019 Enhancement in the Spatial Domain 42
Sharpening Filters
)(2
xf
)( xf
)()(2
xfxf
shaper
transition
Laplacian based filter : an example
if center coefficient <0
if center coefficient >0
The sharpening effect in 1-D
yxfCyxf
yxfCyxfyxf
s
,,
,,,
2
2
8/21/2019 Enhancement in the Spatial Domain 43
Sharpening Filters
Laplacian based filter: a mask example
= 1 0 0
0 0 0
0 0 0
-4 1 1
1 0 0
1 0 0
4C+1 - C - C
-C 0 0
- C 0 0
-C
8/21/2019 Enhancement in the Spatial Domain 44
Sharpening Filters
Laplacian Filter: application example
Imagem Original C=4
C=10 C=6
C=2
C=8
8/21/2019 Enhancement in the Spatial Domain 45
Sharpening Filters
Unsharp masking
Subtracts a blurred version of an image from the image
itself
Example of a mask
yxfyxfyxfum
,,,
= 1 0 0
0 0 0
0 0 0
8/9 -1/9 -1/9
-1/9 -1/9 -1/9
-1/9 -1/9 -1/9
- 1 1 1
1 1 1
1 1 1
1/9
output of a smoothing filter
8/21/2019 Enhancement in the Spatial Domain 46
Sharpening Filters
Filter High-Boost
It is a generalization of unsharp masking, given by
If we elect to use the Laplacian filter for sharpening
if center coefficient <0
if center coefficient >0
1for ,,, AyxfyxAfyxfhb
output of a sharpening filter
yxfyxAf
yxfyxAfyxf
hb
,,
,,,
2
2
1for ,,1, AyxfyxfAyxfshb
8/21/2019 Enhancement in the Spatial Domain 47
Sharpening Filters
Filter High-Boost: example
original
image
high-boost
with A=1
laplacian
high-boost
with A=1.7
8/21/2019 Enhancement in the Spatial Domain 48
Sharpening Filters
The Gradient
y
f
x
f
f
2/122
y
f
x
fmagf f
8/21/2019 Enhancement in the Spatial Domain 49
Sharpening Filters
Masks for the Gradient
-1 0
0 1
0 -1
1 0
Roberts
0 0 0
1 1 1
-1 -1 -1
0 1 -1
0 -1
1
0 -1 1
Prewitt
0 0 0
2 1 1
-2 -1 -1
0 2 -2
0 -1
1
0 -1 1
Sobel
8/21/2019 Enhancement in the Spatial Domain 50
Sharpening Filters Gradient: example
original image
|Gx|+|Gy| (sobel)
|Gy| (sobel) |Gx| (sobel)
8/21/2019 Enhancement in the Spatial Domain 51
Next Topic
Image Enhancement
in the Frequency
Domain