Sie sind auf Seite 1von 39

Digital image processing

quantization

Chapter 3. Image sampling and

IMAGE SAMPLING AND IMAGE QUANTIZATION


1. Introduction
2. Sampling in the two-dimensional space
Basics on image sampling
The concept of spatial frequencies
Images of limited bandwidth
Two-dimensional sampling
Image reconstruction from its samples
The Nyquist rate. The alias effect and spectral replicas superposition
The sampling theorem in the two-dimensional case
Non-rectangular sampling grids and interlaced sampling
The optimal sampling
Practical limitations in sampling and reconstruction
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


quantization

Chapter 3. Image sampling and

1.

Introduction

Fig 1 Image sampling and quantization / Analog image display

Digital image processing


quantization

Chapter 3. Image sampling and

Sampling in the two-dimensional space


Basics on image sampling
f(x,y)

2.

Digital image processing


quantization

Chapter 3. Image sampling and

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 doesnt vary in time (is constant)


= has 0 A.C. component, and only a D.C.
component

A perfectly uniform image (it has the same


brightness in all spatial locations); the D.C.
component = the brightness in any point

The frequency content of a 1-D signal is


proportional to the speed of variation of its
instantaneous value in time:
max ~ max(df/dt)

The frequency content of an image (2-D signal) is


proportional to the speed of variation of its
instantaneous value in space:
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
vector: u=[u(0) u(1) u(N-1)], N samples; the
position of the sample = the discrete time moment

Discrete image (2-D signal): described by its


samples, but in 2-D => a matrix: U[MN],
U={u(m,n)}, m=0,1,,M-1; n=0,1,,N-1.

The spectrum of the time varying signal = the real


part of the Fourier transform of the signal, F();
=2.

The spectrum of the image = real part of the


Fourier transform of the image = 2-D
generalization of 1-D Fourier transform, F(x,y)
x=2x; y=2y

Digital image processing


quantization

Chapter 3. Image sampling and

Images of limited bandwidth


Limited bandwidth image = 2-D signal with finite spectral support:
F(x, y) = the Fourier transform of the image:

F x , y f x, y e

j x x j y y

dxdy f x, y e

j 2 x x y y

dxdy.

F ( x , y ) 0,| x | x 0 ,| y | y 0

Thespectrumofalimitedbandwidthimageanditsspectralsupport

Digital image processing


quantization

Chapter 3. Image sampling and

Two-dimensional sampling (1)


The common sampling grid = the uniformly spaced, rectangular grid:

g ( x, y ) ( x, y )

( x mx, y ny )

m n

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
,
0
,
otherwise

f s ( x, y )
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


quantization

Chapter 3. Image sampling and

Two-dimensional sampling (2)


Question: How to choose the values x, y to achieve:
-the representation of the digital image by the min. number of samples,
-at (ideally) no loss of information?
(I. e.: for a perfectly uniform image, only 1 sample is enough to completely represent the image =>
sampling can be done with very large steps; on the opposite if the brightness varies very sharply => very
many samples needed)
The sampling intervals x, y needed to have no loss of information depend on the spatial frequency
content of the image.
Sampling conditions for no information loss derived by examining the spectrum of the image by
performing the Fourier analysis:
f s ( x, y ) f ( x, y ) g ( x, y ) ( x, y ) Fourier transform :

FS ( x , y ) f S ( x, y ) e j 2 x x e

j 2 y y

dxdy f ( x, y ) g ( x, y ) ( x, y ) e j 2 x x e

j 2 y y

dxdy.

The sampling grid function g(x, y) is periodical with period (x, ly) => can be expressed by its Fourier
k
j 2 x j 2 y

series expansion:
y
x
g ( x, y ) ( x, y )

a(k , l ) e

k l

where :
k

j 2 x j 2 y
1 1 x y
y
x e
a(k , l )
g ( x, y ) ( x, y )e
dxdy.
x y 0 0

Digital image processing


quantization

Chapter 3. Image sampling and

Two-dimensional sampling (3)


Since:

1, if x y 0
,
0
,
otherwise

for ( x, y ) [0; x) [0; y ), g ( x, y ) ( x, y )


a (k , l )

1 1
, k , l ; .
x y

Therefore the Fourier transform of fS is:

2 k x

2 l y

j
j
1

x
FS ( x , y ) f ( x, y )
e
e y

k l x y

j 2 x x
e
e

j 2 y y

l
k

j 2 y y
j 2 x x
1
y
x e

FS ( x , y )
f ( x, y ) e
x y k l

dxdy

l
k

j 2 y y
j 2 x x
1
y
x e

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

dxdy

The spectrum of the sampled image = the collection of an infinite number of scaled spectral replicas

Digital image processing


quantization

Original image

Chapter 3. Image sampling and

Original image spectrum 3D

Original image spectrum 2D

2-D rectangular sampling grid


Sampled image spectrum 3D

Sampled image spectrum 2D

Digital image processing


quantization

Chapter 3. Image sampling and

Image reconstruction from its samples

xs 2 x 0 , ys 2 y 0

H ( x , y )

1
1
,y
2 x 0
2 y 0

1
,( x , y )
( xs ys )
0,
otherwise

~
F ( x , y ) H ( x , y ) Fs ( x , y ) F ( x , y )
~
f x, y h x, y f s x, y
~
f x, y

f s mx, ny h x mx, y ny

m n
Let us assume that the filtering region R is rectangular, at the middle distance between two spectral
replicas:
ys

xs
1
sin x xs sin y ys
,

and

x
y
H ( x , y ) ( xs ys )

2
2 h x, y

y ys
xs
0,
otherwise

~
f x, y

sin x xs m sin y ys n

f
m

x
,
n

y
h
x

x
,
y

f
m

x
,
n

y ys n
xs
m n
m n

Digital image processing


quantization

~
f x, y

Chapter 3. Image sampling and

f s mx, ny sinc x xs m sinc y ys n , where sinc a

m n

sin a
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).

1-D sinc function


2-D sinc function

Digital image processing


quantization

Chapter 3. Image sampling and

The Nyquist rate. The aliasing. The fold-over frequencies

xs 2 x 0 , ys 2 y 0

The Moire effect

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?
By a LPF on the image applied prior to sampling!

Jagged boundaries

Digital image processing


quantization

Chapter 3. Image sampling and

Non-rectangular sampling grids. Interlaced sampling grids


y

1/2

F(x, y)=1

1/ 2

x
1/2

-1/2

-1/2
a) Image spectrum

x
-1

d) The spectrum using G1

e) The spectrum using G2

Interlacedsampling

Optimal sampling = Karhunen-Loeve expansion:

f ( x, y)

m ,n 0

m ,n

m ,n

Digital image processing

Chapter 3. Image sampling and


quantization

Image reconstruction from its samples in the real case

The question is: what to fill in the interpolated (new) dots?


Several interpolation methods are available; ideally sinc function in the spatial domain; in
practice simpler interpolation methods (i.e. approximations of LPFs).

Digital image processing


Image interpolation filters:

Chapter 3. Image sampling and


quantization

Digital image processing

Chapter 3. Image sampling and

Image interpolation examples:

quantization

1. Rectangular (zero-order) filter, or nearest neighbour filter, or box filter:


1/x

-x/2

Original

x/2

Sampled

Reconstructed

Digital image processing

Chapter 3. Image sampling and

Image interpolation examples:

quantization

2. Triangular (first-order) filter, or bilinear filter, or tent filter:


1/x

-x

Original

Sampled

Reconstructed

Digital image processing

Chapter 3. Image sampling and

Image interpolation examples:

quantization

3. Cubic interpolation filter, or bicubic filter begins to better approximate the sinc function:

2x

Original

Sampled

Reconstructed

Digital image processing

Chapter 3. Image sampling and


quantization

Practical limitations in image sampling and reconstruction

Fig. 7 The block diagram of a real sampler & reconstruction (display) system

Fig. 8 The real effect of the interpolation

Digital image processing

Chapter 3. Image sampling and


quantization

3. Image quantization
3.1. Overview

Fig. 9 The quantizers transfer function

Digital image processing

Chapter 3. Image sampling and


quantization

3.2. The uniform quantizer


The quantizers design:
Denote the input brightness range:

u lmin ; LMax

Let B the number of bits of the quantizer => L=2B reconstruction levels
E.g. B=2 => L=4

The expressions of the decision levels:

Uniform quantizer transfer function

t1 l min ; t L 1 LMax

L
l
t
t
q L 1 1 ,t k t k 1 q q Max min
L
L

Reconstruction levels

t k t k 1 t k 1 t k constant q

r4=224

r3=160

r2=96

The expressions of the reconstruction levels:


r1=32

t t
q
rk k k 1 rk t k
2
2

t1=0

t2=64

t3=128
Decision levels

t4=192

Computation of the quantization error: for a given image of size MN pixels,


U non-quantized, and U quantized => we estimate the MSE:

t5=256

Digital image processing

Chapter 3. Image sampling and


quantization

Examples of uniform quantization and the resulting errors:


B=1 => L=2

Non-quantized image

Uniform quantizer transfer function

Quantized image

Reconstruction levels

r2=192

r1=64

t1=0

t2=128
Decision levels

t3=256

Quantization error; MSE=36.2

1000
900
800
700
600
500
400
300
200
100
0
0

50

100

150

200

250

The histogram of the non-quantized image

Digital image processing

Chapter 3. Image sampling and


quantization

Examples of uniform quantization and the resulting errors:


B=2 => L=4

Non-quantized image

Uniform quantizer transfer function

Quantized image

Reconstruction levels

r4=224

r3=160

r2=96

r1=32

t1=0

t2=64

t3=128
Decision levels

t4=192

t5=256

Quantization error; MSE=15

1000
900
800
700
600
500
400
300
200
100
0
0

50

100

150

200

250

The histogram of the non-quantized image

Digital image processing

Chapter 3. Image sampling and


quantization

Examples of uniform quantization and the resulting errors:


B=3 => L=8; false contours present

Non-quantized image

Uniform quantizer transfer function

Quantized image

r8=240

Reconstruction levels

r7=208
r6=176
r5=144
r4=112
r3=80
r2=48
r1=16
t1=0

t2=32

t3=64

t4=96 t5=128 t6=160


Decision levels

t7=192

t8=224

t9=256

Quantization error; MSE=7.33

1000
900
800
700
600
500
400
300
200
100
0
0

50

100

150

200

250

The histogram of the non-quantized image

Digital image processing

Chapter 3. Image sampling and


quantization

3.2. The optimal (MSE) quantizer (the Lloyd-Max quantizer)

(tk rk 1 ) 2 (t k rk ) 2 hu (t k ) 0
t k
t k 1

2 (u rk )hu (u )du 0 1 k L
rk
t
k

t k 1

r r
t k k k 1
2

rk

uhu (u)du

tk
t k 1

E u | u k

hu (u)du

tk

pu (u) pu (tj ),

tj
z k t1

A
t k 1

1
(t j t j 1 ),
2

[hu (u )]

1 / 3

du

t1
t L 1

[hu (u )]
t1

1 / 3

t1
du

t j u t j 1

Digital image processing

Chapter 3. Image sampling and


quantization

12 L2

t L1

t1

[hu (u )]

1/ 3

du

pu(u)

u
t1

t2

(u ) 2

hu (u )
exp
2

2
2
2

(Laplacian)
1

2
(

tj

tj+1

tL+1

h
(
u
)

exp u
u
(Gaussian)
,2 or

variance , - mean)

Digital image processing

Chapter 3. Image sampling and


quantization

Examples of optimal quantization and the quantization error:


B=1 => L=2

Non-quantized image

Nivelele de reconstructie

Functia de transfer a cuantizorului optimal

Quantized image

r2=153

r1=24
t1=0

t2=89
Nivelele de decizie

t3=256

The quantization error;


MSE=19.5

1000
900

The evolution of MSE


in the optimization, starting
from the uniform quantizer

800
38

700

36

600

34

500

32

400

30

300

28

200

26

100

24

22

250

20

The non-quantized image histogram

18

50

100

150

200

Digital image processing

Chapter 3. Image sampling and


quantization

Examples of optimal quantization and the quantization error:


B=2 => L=4

Non-quantized image

Nivelele de reconstructie

Functia de transfer a cuantizorului optimal

Quantized image

r4=181
r3=156

r2=115

r1=20
t1=0

t2=68

t3=136 t4=169
Nivelele de decizie

t5=256

The quantization error;


MSE=9.6

1000

The evolution of MSE


in the optimization, starting
from the uniform quantizer

900
800
15

700
600

14

500
13

400
300

12

200
11

100
0

10

50

100

150

200

250

The non-quantized image histogram

10

Digital image processing

Chapter 3. Image sampling and


quantization

Nivelele de reconstructie

Examples of optimal quantization and the quantization error:


B=3 => L=8

Non-quantized image

Quantized image

Functia de transfer a cuantizorului optimal

r8=224

r7=181
r6=165
r5=147
r4=125
r3=101

r2=54

r1=14
t1=0

t2=34

t3=78

t4=113 t5=136 t6=156t7=173


Nivelele de decizie

t8=203

t9=256

The quantization error; The evolution of MSE


MSE=5
in the optimization, starting
from the uniform quantizer

1000
900
800
700

7.5

600
7

500
400

6.5

300
6

200
100

5.5

0
5

50

100

150

200

250

The non-quantized image histogram

4.5

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 L 1

hu (u ) t L 1 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
t k t k 1 t k 1 t k constant q
2
t t
q
q L 1 1 ,
t k t k 1 q ,
rk t k
L
2
tk

q /2

1
q2
2

u du
q q/ 2
12

2 2B , therefore SNR 10log10 2 2B 6 B dB


2
u

Digital image processing

Chapter 3. Image sampling and


quantization

3.4. Visual quantization methods


In general if B<6 (uniform quantization) or B<5 (optimal quantization) => the "contouring"

effect (i.e. false contours) appears in the quantized image.


The false contours (contouring) = groups of neighbor pixels quantized to the same value <=>
regions of constant gray levels; the boundaries of these regions are the false contours.
The false contours do not contribute significantly to the MSE, but are very disturbing for the
human eye => it is important to reduce the visibility of the quantization error, not only the MSQE.
Solutions: visual quantization schemes, to hold quantization error below the level of visibility.
Two main schemes: (a) contrast quantization; (b) pseudo-random noise quantization

Uniform quantization, B=4

Optimal quantization, B=4

Uniform quantization, B=6

Digital image processing

Chapter 3. Image sampling and


quantization

3.4. Visual quantization methods


a. Contrast quantization
The visual perception of the luminance is non-linear, but the visual perception of contrast is linear
uniform quantization of the contrast is better than uniform quantization of the brightness
contrast = ratio between the lightest and the darkest brightness in the spatial region
just noticeable changes in contrast: 2% => 50 quantization levels needed 6 bits needed with a
uniform quantizer (or 4-5 bits needed with an optimal quantizer)

c ln(1 u ),0 u 1; typ. 6...18, / ln(1 )


or
c u ; typ. 1; 1 / 3

Digital image processing

Chapter 3. Image sampling and


quantization

Examples of contrast quantization:


For c=u1/3:

The transfer function of the contrast quantizer


250

1
0.9

200

0.8

Reconstruction levels

0.7
0.6
0.5

150

100

0.4
0.3

50

0.2
0.1
0

0
t2=3.9844
t1=0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

t3=31.875

t4=107.5781
Decision levels

1000
900
800
700
600
500
400
300
200
100
0
0

50

100

150

200

250

t5=255

Digital image processing

Chapter 3. Image sampling and


quantization

Examples of contrast quantization:


The transfer function of the contrast quantizer

For the log transform:

250

5
4.5

200
Reconstruction levels

4
3.5
3
2.5
2

150

100

1.5

50

1
0.5
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

1000
900
800
700
600
500
400
300
200
100
0

0.8

0.9

0
t1=0

t2=46.0273

t3=102.2733
t4=171.0068
Decision levels

t5=255

Digital image processing

Chapter 3. Image sampling and


quantization

b. Pseudorandom noise quantization (dither)

Large dither amplitude

Uniform quantization, B=4

Prior to dither subtraction

Small dither amplitude

Digital image processing

Chapter 3. Image sampling and


quantization

Digital image processing

Chapter 3. Image sampling and


quantization

Halftone images generation

Fig.14Digitalgenerationofhalftoneimages

Demo: http://markschulze.net/halftone/index.html
Fig.15Halftonematrices

Digital image processing

Chapter 3. Image sampling and


quantization

Fig.3.16

Digital image processing

Chapter 3. Image sampling and


quantization

Color images quantization

Fig.17Colorimagesquantization

Das könnte Ihnen auch gefallen