Professional Documents
Culture Documents
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3: Intensity transformations and spatial filtering
Generic form:
g(x, y) = T [f (x, y)]
Chapter 3
Intensity Transformations & Spatial Filtering
Create a 3x3 mask, and run it over the whole image to generate the new
image (can also use conv2)
Here I have
run the mask
only on the
left half of
the
picture.
© 1992–2008 R. C. Gonzalez & R. E. W ood
s
Tuesday, February 1, 2011
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Create a 3x3 mask, and run it over the whole image to generate the new
image (can also use conv2)
Here I have
run the mask
Example of a blurred
only on the
image by a 3x3
left half of mask
the picture.
© 1992–2008 R. C. Gonzalez & R. E. W ood
s
Tuesday, February 1, 2011
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial
Filtering
Simplest example:
1-pixel neighborhood (the pixel itself), in which case we operate
directly on the intensity of the pixel.
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
useful when one is interested in gray/white areas and the black areas
are dominating
Chapter 3
Intensity Transformations & Spatial Filtering
useful when one is interested in gray/white areas and the black areas
are dominating
Chapter 3
Intensity Transformations & Spatial Filtering
useful when one is interested in gray/white areas and the black areas
are dominating
Chapter 3
Intensity Transformations & Spatial Filtering
useful when one is interested in gray/white areas and the black areas
are dominating
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
s = cr γ
Chapter 3
Intensity Transformations & Spatial
Filtering
s = cr γ
gamma=3
© 1992–2008 R. C. Gonzalez & R. E. Woods
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Contrast stretching by
piecewise linear transformations.
(r1, s1)
(r2, s2)
Control points
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
r1=0=s1
r2=L-1=s2
Identity
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
r1=r2
s1=0, s2=L-1
Thresholding
Chapter 3
Intensity Transformations & Spatial Filtering
r1=r2
s1=0, s2=L-1
Thresholding
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Bit slicing:
0 1 0 1 0 0 1 0
82=64+16+2
© 1992–2008 R. C. Gonzalez & R. E. Woods
Chapter 3
Intensity Transformations & Spatial
Filtering
The reconstructed image is obtained as
2^0*bit_plane1 + 2^1*bit_plane2 + …. + 2^7*bit_plane8
bit plane 1
The most
significant planes
are often those with
high bit number
© 1992–2008 R. C. Gonzalez & R. E. Woods
bit plane 8
Tuesday, February 1, 2011
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Histogram processing
Chapter 3
Intensity Transformations & Spatial
Filtering
Histogram processing
Chapter 3
Intensity Transformations & Spatial Filtering
It is typical to scale nk by MN, the number of pixels. The corresponding number represents the
probability of a pixel having the given intensity.
nk
p(r k ) = p(r k ) = 1
MN k
nk = M N
k Probability that a random pixels has intensity r k .
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
It is typical to scale nk by MN, the number of pixels. The corresponding number represents the probability of a
pixel having the given intensity.
nk
∑ p ( r k )=1
∑ nk= MN p ( r k ) =
MN k
k
Probability that a random pixels has intensity rk.
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) | |
𝑑𝑟
𝑑𝑠
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 )| |
𝑑𝑟
𝑑𝑠
Where does it come from?
ps (s)
p r (r) (Recall, probability
distributions are
positive)
dr ds
r s
s=
The gray regions must have the same area (we are just relabeling the variables)
𝒑 𝒓 ( 𝒓 ) 𝒅𝒓 =𝒑 𝒔 ( 𝒔 ) 𝒅𝒔
(take the absolute value is for the case when T is decreasing)
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
| | 𝑑𝑟 1
𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) 𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) ′ (𝑟)
𝑑𝑠 𝑇
(Alternative formulation)
Chapter 3
Intensity Transformations & Spatial Filtering
| |𝑑𝑟 1
𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) 𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) ′ (𝑟)
𝑑𝑠 𝑇
(Alternative formulation)
Cumulative probability
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
| |𝑑𝑟 1
𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) 𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) ′ (𝑟)
𝑑𝑠 𝑇
(Alternative formulation)
Cumulative probability
Scaling factor so that T(L-1) = L-1
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
What is 𝒑 𝒔 ( 𝒔 ) ?
1
Let’s use the formula 𝑝 𝑠 ( 𝑠 )=𝑝𝑟 ( 𝑟 ) ′ (𝑟)
𝑇
′ 𝑑
𝑇 (𝑟 )= 𝑇 ( 𝑟 )=( 𝐿 − 1) 𝑝 𝑟 ( 𝑟 )
𝑑𝑟
Hence
1 1 1 The uniform
𝑝 𝑠 ( 𝑠 )= 𝑝𝑟 ( 𝑟 ) ′ =𝑝 𝑟 (𝑟 ) =
|𝑇 (𝑟 )| |( 𝐿 −1)𝑝 𝑟 (𝑟 )| 𝐿 −1
distribution!
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Example:
𝐤
𝒔 𝒌 =𝑻 (𝒓 𝒌 ) = ( L − 1) ∑ 𝐩 𝐫 (𝐫 𝐣)
𝐣=𝟎
𝐤
(L − 1)
=
𝐌𝐍 𝐣=𝟎
∑ 𝐧𝐣 k = 0 , …, L − 1
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Example:
k
s k =T (r k ) = ( L − 1) ∑ p r (r j )
j=0
k
(L − 1)
=
MN j=0
∑ nj k = 0 , … , L − 1
Chapter 3
Intensity Transformations & Spatial Filtering
Example:
k
s k =T (r k ) = ( L − 1) ∑ p r (r j )
j=0
k
(L − 1)
=
MN j=0
∑ nj k = 0 , … , L − 1
s1 = 3
s1 = 7 · (0.19 + 0.25) = 3.08
s2 = 5
s3 = 7 · (0.19 + 0.25 + 0.21) = 4.55
and so on...
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Example:
k
s k =T (r k ) = ( L − 1) ∑ p r (r j )
j=0
k
(L − 1)
=
MN j=0
∑ nj k = 0 , … , L − 1
s1 = 3
s1 = 7 · (0.19 + 0.25) = 3.08
s2 = 5
s3 = 7 · (0.19 + 0.25 + 0.21) = 4.55
and so on...
Since the sk is an intensity transformation, it must be an integer
value. This rounding causes the resulting histogram not necessarily
© 1992–2008. R.C. Gonzalez & R. E. Woods to result into a uniform histogram.
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Though the resulting histogram is not uniform, the final result is that
the intensity values are spread out (span a wider range).
Chapter 3
Intensity Transformations & Spatial Filtering
Though the resulting histogram is not uniform, the final result is that
the intensity values are spread out (span a wider range).
NB. Note that the resulting image might reduce the actual number of intensity
levels (because of discretization).
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Seljord lake
(Norwegian equivalent
of Loch Ness)
Chapter 3
Intensity Transformations & Spatial Filtering
Seljord lake
(Norwegian equivalent
of Loch Ness)
Chapter 3
Intensity Transformations & Spatial Filtering
Seljord lake
(Norwegian equivalent
of Loch Ness)
Chapter 3
Intensity Transformations & Spatial Filtering
Matlab command
for histogram Faces
equalization: on
Mars
histeq
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
(Enhancement is
a visual property,
hence partly
subjective).
For landscapes, it works
generally
well. For portraits,
depends
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
dark image
light image
low contrast
high contrast
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Histogram matching
Chapter 3
Intensity Transformations & Spatial Filtering
pr(r) pz(z)
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
equidistribution
pr(r) pz(z)
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
equidistribution
T (r)
pr(r) pz(z)
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
equidistribution
T (r) G(z)
pr(r) pz(z)
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
equidistribution
pr(r) pz(z)
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
equidistribution
pr(r) pz(z)
z = G−1 (s) = G−1 (T (r))
Chapter 3
Intensity Transformations & Spatial Filtering
equidistribution
pr(r) pz(z)
z = G−1 (s) = G−1 (T (r))
Chapter 3
Intensity Transformations & Spatial Filtering
Example:
k
s k =T (r k ) = ( L − 1) ∑ p r (r j )
j=0 G(z0) = 0(0)
s0 = 1
G(z1) = 0(0)
k s1 = 3 (L-1)*cum.prob.
(L − 1)
=
MN j=0
∑ n j k = 0 , … , L − 1
s2 = 5 G(z2) = 0(0)
=7*0.15=1.05
(L-1)*cum.prob.
=7*(0.15+0.2)
s3 = 6 G(z3) = 1(1.05) =2.45
G(z4) = 2(2.45)
s4 = 6
G(z5) = 5(4.55)
s5 = 7
G(z6) = 6(5.95)
s6 = 7
s7 = 7 G(z7) = 7(7)
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7)
Now we can compute the inverse of G for the range of interest.
= 7(7)
s0 = 1
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
© 1992–2008 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
G(z0) = 0(0)
G(z1) = 0(0)
G(z2) = 0(0)
G(z3) = 1(1.05)
G(z4) = 2(2.45)
G(z5) = 5(4.55)
G(z6) = 6(5.95)
G(z7) = 7(7)
s1 = 3
s2 = 5
s3 = 6
s4 = 6
s5 = 7
s6 = 7
s7 = 7
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Definitions:
Average intensity:
𝐿 −1
m = ∑ 𝑟 𝑖 𝑝(𝑟 𝑖 ) (also called mean intensity)
𝑖=1
nth moment:
𝐿 −1
𝜇𝑛 = ∑ (𝑟 𝑖 −𝑚) 𝑝(𝑟 𝑖 )
𝑛
𝑖=1
Second moment:
(this is the intensity
𝐿 −1
𝜇 2 = ∑ (𝑟 𝑖 − 𝑚)2 𝑝(𝑟 𝑖 ) variance, and equals
𝑖=1
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
The mean m (average) and the variance can be computed directly from the
image data,
𝑀 −1 𝑁 −1
1
m= ∑
𝑀𝑁 𝑥=0
∑ 𝑓 (𝑥 , 𝑦)
𝑦 =0
𝑀 −1 𝑁 −1
1
𝜎=2
𝑀𝑁
∑ ∑ ( 𝑓 ( 𝑥 , 𝑦 ) − 𝑚) 2
𝑥=0 𝑦 =0
Chapter 3
Intensity Transformations & Spatial Filtering
𝐿−1
1
𝜎 = ∑ (𝑟 𝑖 −𝑚𝑠 𝑥𝑦 ) 𝑝𝑠 𝑥𝑦 ( 𝑟 𝑖 )= ∑
2 2 2
( 𝑓 ( 𝑠,𝑡 ) −𝑚𝑠 𝑥𝑦 )
𝑖=1 |𝑆 𝑥𝑦|(𝑠 ,𝑡)∈𝑆 𝑥𝑦
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Digital Image Processing, 3rd ed.
Gonzalez & Woods
www.ImageProcessingPlace.com
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
Chapter 3
Intensity Transformations & Spatial Filtering
Chapter 3
Intensity Transformations & Spatial
Filtering
𝑎 𝑏
g( x ,y) = ∑ ∑ 𝑤(𝑠,𝑡) 𝑓 (𝑥+𝑠 , 𝑦+1)
𝑠=− 𝑎 𝑡=− 𝑏