Professional Documents
Culture Documents
1. Introduction
3. Image quantization
4. The optimal quantizer
The uniform quantizer
5. Visual quantization
Contrast quantization
Pseudo-random noise quantization
Halftone image generation
Color image quantization
Digital image processing Chapter 3. Image sampling and quantization
1. Introduction
Digitization
u(m,n) D/A
Computer Display
conversion
Analog display
f(x,y)
y
Digital image processing Chapter 3. Image sampling and quantization
The concept of spatial frequencies
- Grey scale images can be seen as a 2-D generalization of time-varying signals (both in the analog
and in the digital case); the following equivalence applies:
1-D signal (time varying) 2-D signal (grey scale image)
Time coordinate t Space coordinates x,y
Instantaneous value: f(t) Brightness level, point-wise: f(x,y)
A 1-D signal that doesn’t vary in time (is constant) A perfectly uniform image (it has the same
= has 0 A.C. component, and only a D.C. brightness in all spatial locations); the D.C.
component component = the brightness in any point
The frequency content of a 1-D signal is The frequency content of an image (2-D signal) is
proportional to the speed of variation of its proportional to the speed of variation of its
instantaneous value in time: instantaneous value in space:
νmax ~ max(df/dt) νmax,x ~ max(df/dx); νmax,y ~ max(df/dy)
=> νmax,x , νmax,y = “spatial frequencies”
Discrete 1-D signal: described by its samples => a Discrete image (2-D signal): described by its
vector: u=[u(0) u(1) … u(N-1)], N samples; the samples, but in 2-D => a matrix: U[M×N],
position of the sample = the discrete time moment U={u(m,n)}, m=0,1,…,M-1; n=0,1,…,N-1.
The spectrum of the time varying signal = the real The spectrum of the image = real part of the
part of the Fourier transform of the signal, F(ω); Fourier transform of the image = 2-D
ω=2πν. generalization of 1-D Fourier transform, F(ωx,ωy)
ωx=2πνx; ωy=2πνy
Digital image processing Chapter 3. Image sampling and quantization
F x , y f x, y e j x x j y y
e
dxdy f x, y e
j 2 x x y y dxdy.
|F(νx, νy)|
νy
F ( x , y ) 0,| x | x0 ,| y | y0
νy0
-νx0 νx
νx0 νx
νx0
-νy0
-νy0
νy
The Fourier transform of the The spectral support region
limited spectrum image
g(x, y ) ( x, y) ( x mx, y ny)
x m n
y
x
Image sampling = read from the original, spatially continuous, brightness function f(x,y), only in the black
dots positions ( only where the grid allows):
f ( x, y ), x mx, y ny
f s ( x, y ) ,
0 , otherwise
m, n Z.
f s ( x, y) f ( x, y) g(x, y ) ( x, y) f (mx, ny) ( x mx, y ny)
m n
Digital image processing Chapter 3. Image sampling and quantization
The sampling grid function g(Δx, Δy) is periodical with period (Δx, Δy) => can be expressed by its Fourier
series expansion: k l
j 2 x j 2 y
x y
g ( x, y ) ( x, y ) a(k , l ) e e ,
k l
where :
k l
1 1 x y j 2 x j 2 y
x e y
a(k , l ) g ( x, y ) ( x, y )e dxdy.
x y 0 0
Digital image processing Chapter 3. Image sampling and quantization
Since:
1, if x y 0
for ( x, y ) [0; x) [0; y ), g ( x, y ) ( x, y ) ,
0 , otherwise
, k , l ; .
1 1
a(k , l )
x y
Therefore the Fourier transform of fS is:
2 k x 2 l y
j j j 2 y y
e x e y e j 2 x x e
1
FS ( x , y ) f ( x, y ) dxdy
k l x y
k l
j 2 x x j 2 y y
1 x e y
FS ( x , y ) f ( x, y ) e dxdy
x y k l
k l
j 2 x x j 2 y y
1 x e y
FS ( x , y ) f ( x, y ) e dxdy
x y k l
1 k l
FS ( x , y ) F x , y .
x y k l x y
The spectrum of the sampled image = the collection of an infinite number of scaled spectral replicas
of the spectrum of the original image, centered at multiples of spatial frequencies 1/Δx, 1/ Δy.
Digital image processing Chapter 3. Image sampling and quantization
y 1/x
ys
xs 2 x0 , ys 2 y 0 x
1
,y
1
ys-y0
2
2 x 0 2 y 0
2y0 1/y
y0 1
,( , )
H ( x , y ) ( xs ys ) x y
1
3
0, otherwise
2x0 ~
x0 F ( x , y ) H ( x , y ) Fs ( x , y ) F ( x , y )
xs x
f x, y h x, y f s x, y
xs-x0 ~
xs
f x, y
~
sinx xs m sin y ys n
s s
f
m n
mx, ny h x mx, y ny f
m n
mx, ny
x xs m
y ys n
Digital image processing Chapter 3. Image sampling and quantization
f s mx, ny sincx xs msincy ys n, where sinca
sin a
f x, y
~
m n a
Since the sinc function has infinite extent => it is impossible to implement in practice the ideal LPF
it is impossible to reconstruct in practice an image from its samples without error if we sample it
at the Nyquist rates.
Practical solution: sample the image at higher spatial frequencies + implement a real LPF (as close to
the ideal as possible).
xs 2 x 0 , ys 2 y 0
y
y0
0 2 y0
2 x0
The Moire effect
0 x0 x
Fig. 5 Aliasing – fold-over frequencies
Note: Aliasing may also appear in the reconstruction process,
due to the imperfections of the filter!
How to avoid aliasing if cannot increase the sampling frequencies?
“Jagged” boundaries
By a LPF on the image applied prior to sampling!
Digital image processing Chapter 3. Image sampling and quantization
Non-rectangular sampling grids. Interlaced sampling grids n
n
νy F(νx, νy)=1
1/2 2
1/ 2
νx 1
1 2 2
-1/2 1/2
-1 0 1 1 2 3 m -2 -1 0 1 2 m
-1/2
2 2
1
x x
-1 0 1
1 1
x x
p0(x) 4x0
1/x 1
Triangular 1 x
2
tri sinc 1 sinc 2
(first order x x p1 ( x) p1 ( y)
2x 0 2y 0
filter) -x x x x
p0 ( x) p0 ( x)
0 0
p1(x) 4x0
1
n-order filter
n 1
pn(x) 4x0
1
1 x2 1 ( x2 y2 )
2 2 2 exp
exp
Gaussian 2 2 2 2 exp 2 2 2 (12 22 )
2
pg(x) 0
x
0
x
2
1 x 1 x y
sinc sinc sinc rect 1 rect 2
Sinc 0
x x x xy x y 2x 0 2y 0 0
2x 2x0
Digital image processing Chapter 3. Image sampling and quantization
1/x
-x/2 x/2 x
0
1/x
-x x x
0
3. Cubic interpolation filter, or bicubic filter – begins to better approximate the sinc function:
x
0
2x
Fig. 7 The block diagram of a real sampler & reconstruction (display) system
Pa(1,0)
Interpolation filter or
display system spectrum
-xs/2 xs/2 1
- 0
0
-xs/2 xs/2
Interpolation error
3. Image quantization
3.1. Overview
Quantizer’s
u u’ output
Quantizer rL
rk
t1 t2 tk tk+1 tL+1
Quantization
r2 error
r1
t k t k 1 t k 1 t k constant q
Reconstruction levels
r3=160
t l
q L 1 1 ,tk tk 1 q q Max min
t L
L L r2=96
t t
rk k k 1 rk t k
q
t1=0 t2=64 t3=128 t4=192 t5=256
2 2 Decision levels
• Computation of the quantization error: for a given image of size M×N pixels,
U – non-quantized, and U’ – quantized => we estimate the MSE:
1 M 1N 1 L t k 1
um, n u ' m, n (u rk ) 2 hlin,U (u)du
2
MN m 0 n 0 k 1 t k
Digital image processing Chapter 3. Image sampling and quantization
r2=192
Reconstruction levels
r1=64
900
800
700
600
500
400
300
200
100
r4=224
Reconstruction levels
r3=160
r2=96
r1=32
900
800
700
600
500
400
300
200
100
r7=208
r6=176
Reconstruction levels
r5=144
r4=112
r3=80
r2=48
r1=16
800
700
600
500
400
300
200
100
t L 1 L ti 1
e E[(u u' ) ] (u u' ) hu (u)du
2 2
(u ri ) 2 hu (u )du
t1 i 1 ti
tk
(tk rk 1 ) 2 (tk rk ) 2 hu (tk ) 0
t k 1
2 (u rk )hu (u )du 0 1 k L
rk t k
t k 1
r r
uhu (u)du
t k k k 1 rk E u | u k
tk
t k 1
2
hu (u)du
tk
1
pu (u) pu (tj ), tj (t j t j 1 ), t j u t j 1
z k t1
2
[hu (u )]
1 / 3
A du
t k 1 t1
t1
t L 1
[hu (u )]
1 / 3
du
t1
Digital image processing Chapter 3. Image sampling and quantization
3
1 t
L 1
[hu (u )] du
1/ 3
12 L2 t
1
pu(u)
u
t1 t2 tj tj+1 tL+1
(u ) 2
exp u
1
hu (u ) exp
(Gaussian) , or hu (u ) (Laplacian)
2
2
2 2
2
2
2 ( variance , - mean)
Digital image processing Chapter 3. Image sampling and quantization
r2=153
r1=24
800
from the uniform quantizer
38
700
36
600
34
500
32
400
30
300
28
200 26
100 24
0 22
20
0 50 100 150 200 250
18
The non-quantized image histogram 1 2 3 4 5 6 7 8
Digital image processing Chapter 3. Image sampling and quantization
r4=181
r3=156
r2=115
r1=20
600
14
500
13
400
300 12
200
11
100
0 10
r8=224
Nivelele de reconstructie
r7=181
r6=165
r5=147
r4=125
r3=101
r2=54
r1=14
400
6.5
300
6
200
100 5.5
0
5
0 50 100 150 200 250
4.5
The non-quantized image histogram 0 2 4 6 8 10 12 14
Digital image processing Chapter 3. Image sampling and quantization
3.3. The uniform quantizer = the optimal quantizer for the uniform grey level
distribution:
1
, t1 u t L1
hu (u ) t L1 t1
0 otherwise
(t k21 t k2 ) t k 1 t k
rk
2(t k 1 t k ) 2
t k 1 t k 1 tk tk 1 tk 1 tk constant q
tk
2
t t q
q L1 1 , t k t k 1 q, rk t k
L 2
q /2
1 q2
q q/ 2
u du
2
12
22B , therefore SNR 10log10 22B 6 B dB
u2
Digital image processing Chapter 3. Image sampling and quantization
Brightness
-
f( ) c MMSE c’ f 1( ) u’
u brightness- contrast -
quantizer
contrast brightness
0.9
200
0.8
0.7
150
Reconstruction levels
0.6
0.5
100
0.4
0.3
50
0.2
0.1
0
t2=3.9844
t1=0 t3=31.875 t4=107.5781 t5=255
Decision levels
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
1000
900
800
700
600
500
400
300
200
100
4.5
200
4
Reconstruction levels
3.5
150
3
2.5
100
2
1.5
1 50
0.5
0 0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 t1=0 t2=46.0273 t3=102.2733 t4=171.0068 t5=255
Decision levels
1000
900
800
700
600
500
400
300
200
100
u’(m,n)
u(m,n) v(m,n) K bits v’(m,n)
quantizer
+ +
+ -
(m,n)
Uniformly distributed
pseudorandom noise,
[-A,A] Large dither amplitude
Fig. 13
a b a. 3 bits quantizer =>visible false contours;
c d b. 8 bits image, with pseudo-random noise added in the range [-16,16];
c. the image from Figure b) quantized with a 3 bits quantizer
d. the result of subtracting the pseudo-random noise from the image in
Figure c)
Digital image processing Chapter 3. Image sampling and quantization
Thresholding
v’
Luminance v(m,n) v’(m,n)
Halftone
+
0 u(m,n) A + display
+
A
0 (m,n) A
Pseudorandom matrix
Fig.14 Digital generation of halftone images
Fig.3.16
Digital image processing Chapter 3. Image sampling and quantization
RN T1 T1’ RN’
Quantizer