View
4
Download
0
Category
Preview:
Citation preview
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Intensity transformation T maps the
intensity r0 of a pixel, P, to a new
intensity value s0=T(r0 ).
The mapping is performed using a
transfer function
Examples of two transfer functions
T
• Transformation function does not take
into the intensity of adjacent pixels.
• It does not increase the number of
intensity values available.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Spatial Filter F maps the intensity Ii of
a pixel, Pi, to a new intensity value
based on its neighborhood.
T
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Example of Intensity Transformations.
• They map L intensity values
a new L intensity value
T
r0
s0
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Intensity transformation – Negative
Original mammogram (left) and
the negated mammogram
0 L
L
r0
s0
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Intensity transformation – Log
Original Fourier spectrum (left) and
the log transformed spectrum (right)
with c = 1
r0
s0
)1log( rcs
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Power-Law (Gamma) Transformations
Where c and γ are positive constants.
It also sometime written as:
crs
)( rcs
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Gamma correction
Gamma correction aims to improve the
correctness of an image when display
on a screen.
Gamma correction controls the overall
brightness of an image.
Incorrect images can look either
bleached out, or too dark.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Gamma correction
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Image Histogram
The image histogram of a digital image with intensity
levels in the range [0,L-1] is a discrete function h(rk) =nk ,
where rk is the kth intensity value and nk is the number of
pixels in the image with the intensity rk
Histogram Normalization
It is common to normalize the histogram by dividing nk by
the number of pixels in the image. The normalized
intensity p(rk)= nk /MN estimates the probability of
occurrence of intensity level rk in an image
int[] histogram(Mat img){
int hist[256] ;
memset(hist, 0, 256);
for ( int row = 0 ; row < img.rows; row++)
for ( int col = 0 ; col < img.cols; col++ )
hist[img.at<uchar>(row, col)]++ ;
return hist ;
}
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Histogram Equalization
In general we assume
1. T(r) is monotonically increasing
2. 0 ≤ T(r) ≤ L-1 for 0 ≤ r ≤ L-1
Let pr(r) and ps (s) be a probability
density functions. If we assume pr(r) and
T(r) are know, the
ds
drrpsp rs )()(
Image processing interests on the following
formulation, where the right side is the
cumulative distribution function
r
r dwwpLrTs0
)()1()(
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
)()1()()1()(
0
rpLdwwpdr
dL
dr
rdT
dr
dsr
r
r
Use the previous formulation yields, a uniform
probability density function
1
1
)()1(
1)()()(
LrpLrp
ds
drrpsp
r
rrs
Histogram equalization determine the
transformation that seek to produce an
output image that has a uniform histogram.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Example:
1
1
2
)1(
)1(
2
1)1(
2
)1(
2)()(
11
2)()1()(
0
10;)1(
2
)(
2
12
2
1
2
0
2
0
2
Lr
L
L
r
L
r
dr
d
L
r
dr
ds
L
r
ds
drrpsp
L
rwdw
LdwwpLrTs
otherwise
LrL
r
rp
rs
rr
r
r
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Histogram Equalization
In the discrete case
1,..,2,1,0;)1(
)()1()(00
LknMN
LrpLrTs
k
j
j
k
j
jrkk
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Example:
A 3bit image of size 64x64
[0, L-1] =[0,7]
08.3)(7)(7)(7)(
33.1)(7)(7)(
10
1
0
11
0
0
0
00
rprprprTs
rprprTs
rr
j
jr
r
j
jr
00.7,86.6,65.6,23.6,67.5,55.4 765432 ssssss
We round the s values to get values of the equalized histogram
equalized histogram
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Histogram Matching
Let us assume histograms are continuous functions, and let T(r) defined as earlier and G(z)
defined similarly, then
r
r dwwpLrTs0
)()1()(
z
z dttpLzGs0
)()1()(
Since T(r) = G(z), then
)()]([ 11 sGrTGz
This shows that that an image whose intensity levels have a specific probability density
function can be obtained as follow:
1. Obtain pr(r) from the input image and determine the value of s (as above)
2. Use a specified PDF to obtain the transformation function G(z)
3. Compute the inverse transformation z=G-1(s)
4. Obtain the output image by first equalizing the input image (intensity are the s values)
for each intensity (s value) perform the inverse mapping z = G-1(s) to obtain the
corresponding pixel in the output image
And
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Example:
rz
z
rr
r
r
L
zdww
LdwwpLzG
L
rwdw
LdwwpLrTs
otherwise
LrL
r
rp
0 2
22
0 2
0
2
0
2
11
3)()1()(
11
2)()1()(
0
10;)1(
2
)(
3/12
2
3
)1(
)1(
sLz
L
zs
Now we can compute the values of z by
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Example:
A 3bit image of size 64x64
[0, L-1] =[0,7]
0 1 2 3 4 5 6 7
1 3 5 6 7 7 7 7
The s values from the previous example
00.0)](7)([7)(7)(
00.0)(7)(7)(
10
1
0
1
0
0
0
0
zpzpzpzG
rprpzG
rr
j
jz
r
j
jz
0 1 2 3 4 5 6 7
0.0 0.0 0.0 1.05 2.45 4.55 5.95 7.00
The G(z) values from the previous example
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Local Histogram
Local histogram represents the distribution
of intensity over a window (sub-image).
Local Histogram Equalization is performed
according to this window.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Image Moment
The nth moment of an image is defines as
The intensity variance is defines as
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
1
1
1
1
),(),(),(i j
jyixfjiwyxg
Spatial Filtering
Applying a 3x3 filter ,w, on the image f
Applying a general (2ax2b) filter ,w, on the
image f
a
ai
b
bj
jyixfjiwyxg ),(),(),(
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Correlation
Is the process of moving a filter mask
over the image and computing the sum
of products at each location.
Convolution
moves the reversed filter mask over
the image and computing the sum of
products at each location.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Correlation and Convolution in the
2D space.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
3x3 Spatial filters, which result in a blurring effect. The
blurring depends on the ration between the central value
and the “boundary” values.
The effect of applying averaging filters of size 3,5,9, 15,
and 35.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Smoothing filters – Gaussian Based
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
In many application we often
apply multiple filters and
some of them may appear
contradicting from the first
glance.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
An Image as a Function
• We could think about an image row, as a
one dimensional function,
– x is the position of the pixel
– y is the color of the pixel-grayscale.
• Similarly, 2D image could be treated as
3D function.
• Actually these functions are not 3D, but
2.5 D as there is one value for each x, y
value
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
An Image as a Function
• As we treat image as a function
– It is possible to compute is
derivative, but we need to
exchange ∆x by 1.
• It is possible to compute the first
and the second derivative of an
image.
• Derivative help in determining local
minima, local maxima, and change
in derivative direction
)()1(1
)()1()('
)()('lim)('
0
xIxIxIxI
xI
x
xfxxfxf
x
)()1(2)2(
)()1()1()2(
1
)(')1(')(''
)(')('lim)(''
0
xIxIxI
xIxIxIxI
xIxIxI
x
xfxxfxf
x
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
First & Second Derivatives
• Let us consider a vertical cut on the
first two images
• The function we get are below each
images
• The first derivative
• Second Derivative
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Gradient Operator
The Gradient Operator for an
image f at the location (x, y) is
Which is often approximated by:
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Laplacian Operator
The Laplace operator is a second order differential operator in the n-dimensional
Euclidean space, defined as the divergence (∇·) of the gradient (∇ƒ).
If ƒ is a twice-differentiable real-valued function, then the Laplacian of ƒ is defined by
The Laplacian Operator for an image f at the location (x, y) is
defined similarly
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Image Filter
Image Filters change the appearance of an image or part of an image by altering the values
of its pixels.
Image Blur
Median Filter
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Set Theory
One way of defining a set A is in terms of its characteristic function . An element
x belongs to set A if and only if , where .
In such a scheme we define set operation as:
• Union as
• Intersection as
• Complement as
• Set Inclusion as if and only if (for all x) implies
• Set Equality as A = B if and only if (for all x)
1)( xA }1,0{:)( UxA
))(),(max()( xxx BABA
))(),(min()( xxx BABA
)(1)( xx AA
)(xA
1)( xA
1)( xA 1)( xB
)()( xx BA
BA x
x
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Fuzzy Set Theory
A fuzzy set is defined in terms of a membership function .
A characteristic function is a special case of a membership function and a regular set is a
special case of a fuzzy set.
The set operations are defined as:
• Union as
• Intersection as
• Complement as
• Set inclusion as if and only if (for all x)
• Set Equality as A = B if and only if (for all x)
]1,0[: UA
))(),(max()( xxx BABA
))(),(min()( xxx BABA
)(1)( xx AA
)()( xx BA
)()( xx BA
BA x
x
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Illustrating The membership functions of regular and fuzzy set
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
zabcbcczS
czcbcbczSzShapeBell
otherwise
dbzbac
az
bzaac
az
az
cbazSShapeS
otherwise
za
azbabza
zSigma
otherwise
dbzbcaz
bza
azcabza
zTrapezodal
otherwise
cazacaz
azbabza
zTriangle
),2/,,(1
),2/,,()(:
0
21
2
0
),,;(:
0
1
/)(1
)(:
0
/)(1
1
/)(1
)(:
0
/)(1
/)(1
)(:
2
2
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Rule-Based classification of using
fuzzy sets.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Using fuzzy sets for intensity
transformation
1. Define a set of rules to change pixel
intensity.
2. Transfer the rules into fuzzy set
3. User the rules to change intensity
Example:
1. If a pixel is dark, then make it darker
2. If a pixel is gray, then make it gray
3. If a pixel is bright, then make it brighter
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Using fuzzy sets for intensity
transformation
1. Define a set of rules to change pixel
intensity.
2. Use fuzzy set to apply this rules.
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
www.ImageProcessingPlace.com
© 1992–2008 R. C. Gonzalez & R. E. Woods
Gonzalez & Woods
Chapter 3 Intensity Transformations & Spatial Filtering
Using fuzzy sets for spatial filtering
Recommended