39
Digital image processing Chapter 3. Image sampling and quantization 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 Chapter 3. Image sampling and quantization

  • Upload
    twyla

  • View
    270

  • Download
    23

Embed Size (px)

DESCRIPTION

Digital image processing Chapter 3. Image sampling and quantization. IMAGE SAMPLING AND IMAGE QUANTIZATION 1. Introduction 2. Sampling in the two-dimensional space Basics on image sampling The concept of spatial frequencies - PowerPoint PPT Presentation

Citation preview

Page 1: Digital image processing           Chapter 3.  Image sampling and quantization

Digital image processing Chapter 3. Image sampling and quantization

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

Page 2: Digital image processing           Chapter 3.  Image sampling and quantization

 

          

 

  

 

       

 

 

1.           Introduction

 

Fig 1 Image sampling and quantization / Analog image display 

Digital image processing Chapter 3. Image sampling and quantization

Page 3: Digital image processing           Chapter 3.  Image sampling and quantization

 

          

 

  

 

       

 

 

2.           Sampling in the two-dimensional space

Basics on image sampling

 

Digital image processing Chapter 3. Image sampling and quantization

x

y

f(x,y)

Page 4: 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:

Digital image processing Chapter 3. Image sampling and quantization

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) = 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[M×N],

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=2πνx; ωy=2πνy

Page 5: Digital image processing           Chapter 3.  Image sampling and quantization

Images of limited bandwidth •Limited bandwidth image = 2-D signal with finite spectral support:

F(νx, νy) = the Fourier transform of the image:

The spectrum of a limited bandwidth image and its spectral support

Digital image processing Chapter 3. Image sampling and quantization

.,,,

2

dxdyeyxfdxdyeeyxfFyxjyjxj

yxyxyx

00 ||,||,0),( yyxxyxF

Page 6: Digital image processing           Chapter 3.  Image sampling and quantization

Two-dimensional sampling (1)

  

m nyxs ynyxmxynxmfyxgyxfyxf ),(),(),(),(),( ),(

Digital image processing Chapter 3. Image sampling and quantization

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

m nyx ynyxmxyxg ),(),(),(

Image sampling = read from the original, spatially continuous, brightness function f(x,y), only in the black dots positions ( only where the grid allows):

.,

,,0

,),,(),(

Z

nm

otherwise

ynyxmxyxfyxfs

Page 7: Digital image processing           Chapter 3.  Image sampling and quantization

• 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:

The sampling grid function g(Δx, Δy) is periodical with period (Δx, Δy) => can be expressed by its Fourier series expansion:

Two-dimensional sampling (2)

  

.),(),(),(),(

:ansformFourier tr),(),(),(

22),(

22

),(

dxdyeeyxgyxfdxdyeeyxfF

yxgyxfyxf

yyjxxjyx

yyjxxjSyxS

yxs

Digital image processing Chapter 3. Image sampling and quantization

x y yyl

jxx

kj

yx

k l

yyl

jxx

kj

yx

dxdyeeyxgyx

lka

eelkayxg

0 0

22

),(

22

),(

.),(11

),(

:where

,),(),(

Page 8: Digital image processing           Chapter 3.  Image sampling and quantization

Since:

Therefore the Fourier transform of fS is:

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.

Two-dimensional sampling (3)

  .,

1),(

),(1

),(

),(1

),(

1),(),(

22

22

2222

k lyxyxS

k l

yl

yyjx

kxxj

yxS

yl

yyjx

kxxj

k lyxS

yyjxxjyyl

jx

xkj

k lyxS

y

l

x

kF

yxF

dxdyeeyxfyx

F

dxdyeeyxfyx

F

dxdyeeeeyx

yxfF

Digital image processing Chapter 3. Image sampling and quantization

.;,,11

),(

,,0

0,1),(),;0[);0[),(for ),(

lkyx

lka

otherwise

yxifyxgyxyx yx

Page 9: Digital image processing           Chapter 3.  Image sampling and quantization

Digital image processing Chapter 3. Image sampling and quantization

Original image Original image spectrum – 3D Original image spectrum – 2D

2-D rectangular sampling grid

Sampled image spectrum – 3D Sampled image spectrum – 2D

Page 10: Digital image processing           Chapter 3.  Image sampling and quantization

Image reconstruction from its samples

00 2,2 yysxxs 00 2

1,

2

1

yx

yx

otherwise ,0

),(,)(

1),( yx

ysxsyxH

m nynyxmxhynxmsfyxf

yxsfyxhyxf

yxFyxsFyxHyxF

,,,~

,,,~

),(),(),(),(~

Digital image processing Chapter 3. Image sampling and quantization

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

ysy

ysy

xsxxsx

yxhys

yxs

xysxsyxH

sinsin

,

otherwise ,0

2 and

2,

)(

1),(

nysy

nysy

mxsx

mxsx

m nynxmsf

m nynyxmxhynxmsfyxf

sinsin,,,,

~

Page 11: Digital image processing           Chapter 3.  Image sampling and quantization

Digital image processing Chapter 3. Image sampling and quantization

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 itat the Nyquist rates.

Practical solution: sample the image at higher spatial frequencies + implement a real LPF (as close to the ideal as possible).

a

aanysymxsx

m nynxmsfyxf

sinsinc where,sincsinc,,

~

1-D sinc function2-D sinc function

Page 12: Digital image processing           Chapter 3.  Image sampling and quantization

The Nyquist rate. The aliasing. The 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?

By a LPF on the image applied prior to sampling!

00 2,2 yysxxs

Digital image processing Chapter 3. Image sampling and quantization

The Moire effect

“Jagged” boundaries

Page 13: Digital image processing           Chapter 3.  Image sampling and quantization

Non-rectangular sampling grids. Interlaced sampling grids

a) Image spectrum

1 2/

F(νx, νy)=1

νx

νy

1/2

1/2

-1/2

-1/2

b) Rectangular grid G1

n

m -1 3 2 1 0 1

1

c) Interlaced grid G2

n

2

1 2 2

1 -1 -2 2 0 m

d) The spectrum using G1

x

x x

x

1

-1 1 0

2

1

e) The spectrum using G2

1

2

Interlaced sampling 

Digital image processing Chapter 3. Image sampling and quantization

f x y am n m nm n

( , ) , ,,

0

Optimal sampling = Karhunen-Loeve expansion:

Page 14: 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 Chapter 3. Image sampling and quantization

Page 15: Digital image processing           Chapter 3.  Image sampling and quantization

The 1-D interpolation

function

Graphical representation

p(x)

The 2-D interpolation

function pa(x,y)=p(x)p(y)

Frequency response pa(1,2)

pa(1,0)

Rectangular (zero-order

filter) p0(x)

0 x

1/x

x/2 -x/2

1

xrect

x

x

p x p y0 0( ) ( )

sinc sinc

1

0

2

02 2x y

4x0 0

1

x

Triangular (first order

filter) p1(x)

x -x 0

x

1/x

1

xtri

x

x

p x p x0 0( ) ( )

p x p y1 1( ) ( )

sinc sinc

1

0

2

0

2

2 2x y

4x0

0

1

x

n-order filter

n=2, quadratic n=3, cubic spline

pn(x)

0 x

p x p x

n0 0( ) ( ) convolu@ii

p x p yn n( ) ( )

sinc sinc

1

0

2

0

1

2 2x y

n

4x0

0

1

x

Gaussian pg(x)

20

x

1

2 22

2

2 exp

x

1

2 22

2 2

2 exp

( )

x y

exp ( ) 2 2 212

22

0

1

x

Sinc

2x

0 x

1

x

x

xsinc

1

x y

x

x

y

ysinc sinc

rect rectx y

1

0

2

02 2

1

2x0

0

 Image interpolation filters:

Digital image processing Chapter 3. Image sampling and quantization

Page 16: Digital image processing           Chapter 3.  Image sampling and quantization

 Image interpolation examples:

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

Digital image processing Chapter 3. Image sampling and quantization

0x

1/x

x/2-x/2

Original Sampled Reconstructed

Page 17: Digital image processing           Chapter 3.  Image sampling and quantization

 Image interpolation examples:

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

Digital image processing Chapter 3. Image sampling and quantization

Original Sampled Reconstructed

x-x0

x

1/x

Page 18: Digital image processing           Chapter 3.  Image sampling and quantization

 Image interpolation examples:

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

Digital image processing Chapter 3. Image sampling and quantization

Original Sampled Reconstructed

2x

0 x

Page 19: 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

Page 20: Digital image processing           Chapter 3.  Image sampling and quantization

3. Image quantization3. Image quantization  

 

Fig. 9 The quantizer’s transfer function

Digital image processing Chapter 3. Image sampling and quantization

3.1. Overview

Page 21: Digital image processing           Chapter 3.  Image sampling and quantization

3.2. The uniform quantizer

The quantizer’s design:

• Denote the input brightness range:

• Let B – the number of bits of the quantizer => L=2B reconstruction levels

• The expressions of the decision levels:

• The expressions of the reconstruction 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:

221 q

ktkrktkt

kr

t t t t qk k k k 1 1 constant

LminlMaxL

qqktktL

tLtq

1,11

Digital image processing Chapter 3. Image sampling and quantization

MaxLLtlt 1;min1

MaxLminlu ;

E.g. B=2 => L=4

t1=0 t2=64 t3=128 t4=192 t5=256

r1=32

r2=96

r3=160

r4=224

Uniform quantizer transfer function

Decision levels

Re

co

ns

tru

cti

on

le

ve

ls

Page 22: Digital image processing           Chapter 3.  Image sampling and quantization

Examples of uniform quantization and the resulting errors:

Digital image processing Chapter 3. Image sampling and quantization

B=1 => L=2

t1=0 t2=128 t3=256

r1=64

r2=192

Uniform quantizer transfer function

Decision levels

Re

co

ns

tru

cti

on

le

ve

ls

Non-quantized image Quantized image

Quantization error; MSE=36.2

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

The histogram of the non-quantized image

Page 23: Digital image processing           Chapter 3.  Image sampling and quantization

Examples of uniform quantization and the resulting errors:

Digital image processing Chapter 3. Image sampling and quantization

B=2 => L=4Non-quantized image Quantized image

Quantization error; MSE=15

The histogram of the non-quantized image

t1=0 t2=64 t3=128 t4=192 t5=256

r1=32

r2=96

r3=160

r4=224

Uniform quantizer transfer function

Decision levels

Rec

onst

ruct

ion

leve

ls

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

Page 24: Digital image processing           Chapter 3.  Image sampling and quantization

Examples of uniform quantization and the resulting errors:

Digital image processing Chapter 3. Image sampling and quantization

B=3 => L=8; false contours present Non-quantized image Quantized image

Quantization error; MSE=7.33

The histogram of the non-quantized image

t1=0 t2=32 t3=64 t4=96 t5=128 t6=160 t7=192 t8=224 t9=256

r1=16

r2=48

r3=80

r4=112

r5=144

r6=176

r7=208

r8=240

Uniform quantizer transfer function

Decision levels

Rec

onst

ruct

ion

leve

ls

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

Page 25: Digital image processing           Chapter 3.  Image sampling and quantization

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

Lkduuhrur

thrtrtt

k

k

t

tuk

k

kukkkkk

10)()(2

0)()()(

1

221

tr r

kk k 1

2 kt

tu

t

tu

k u|uE

(u)duh

(u)duuh

r1k

k

1k

k

p u p t t t t t u tu u j j j j j j( ) ( ), ( ),

1

2 1 1

Digital image processing Chapter 3. Image sampling and quantization

13/1

3/1

11

1

1

1

)]([

)]([

t

duuh

duuhA

tL

k

t

tu

tz

tu

k

Page 26: Digital image processing           Chapter 3.  Image sampling and quantization

tj+1

pu(u)

u

t2 tL+1tjt1

(Gaussian) , or

(Laplacian) 

( variance , - mean)

2

2

2 2

)(exp

2

1)(

uuhu

uuhu exp

2)(

22

3

3/12

1

1

)]([12

1

Lt

tu duuh

L

Digital image processing Chapter 3. Image sampling and quantization

Page 27: Digital image processing           Chapter 3.  Image sampling and quantization

Examples of optimal quantization and the quantization error:B=1 => L=2

Non-quantized image Quantized image

The quantization error; MSE=19.5

The non-quantized image histogram

t1=0 t2=89 t3=256

r1=24

r2=153

Functia de transfer a cuantizorului optimal

Nivelele de decizie

Niv

ele

le d

e r

ec

on

str

uc

tie

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

The evolution of MSE in the optimization, startingfrom the uniform quantizer

1 2 3 4 5 6 7 818

20

22

24

26

28

30

32

34

36

38

Digital image processing Chapter 3. Image sampling and quantization

Page 28: Digital image processing           Chapter 3.  Image sampling and quantization

B=2 => L=4

The quantization error; MSE=9.6

t1=0 t2=68 t3=136 t4=169 t5=256

r1=20

r2=115

r3=156

r4=181

Functia de transfer a cuantizorului optimal

Nivelele de decizie

Niv

ele

le d

e r

ec

on

str

uc

tie

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

1 2 3 4 5 6 7 8 9 109

10

11

12

13

14

15

Examples of optimal quantization and the quantization error:

Non-quantized image Quantized image

The non-quantized image histogram

The evolution of MSE in the optimization, startingfrom the uniform quantizer

Digital image processing Chapter 3. Image sampling and quantization

Page 29: Digital image processing           Chapter 3.  Image sampling and quantization

B=3 => L=8

The quantization error; MSE=5

t1=0 t2=34 t3=78 t4=113 t5=136 t6=156t7=173 t8=203 t9=256

r1=14

r2=54

r3=101

r4=125

r5=147

r6=165

r7=181

r8=224

Functia de transfer a cuantizorului optimal

Nivelele de decizie

Niv

ele

le d

e r

ec

on

str

uc

tie

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

0 2 4 6 8 10 12 144.5

5

5.5

6

6.5

7

7.5

Digital image processing Chapter 3. Image sampling and quantization

Examples of optimal quantization and the quantization error:

Non-quantized image Quantized image

The non-quantized image histogram

The evolution of MSE in the optimization, startingfrom the uniform quantizer

Page 30: Digital image processing           Chapter 3.  Image sampling and quantization

3.3. The uniform quantizer = the optimal quantizer for the uniform grey level distribution:

otherwise

tutttuh

LLu

0

,1

)(11

11

rt t

t t

t tk

k k

k k

k k

( )

( )1

2 2

1

1

2 2

tt t

kk k

1 1

2t t t t qk k k k 1 1 constant

qt t

Lt t q r t

qLk k k k

1 1

1 2, ,

1

122

2

2 2

qu du

q

q

q

/

/

dBB6210logSNR,2 2B10

2B2u

therefore

Digital image processing Chapter 3. Image sampling and quantization

Page 31: 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

Digital image processing Chapter 3. Image sampling and quantization

Uniform quantization, B=4 Uniform quantization, B=6Optimal quantization, B=4

Page 32: 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)

 

3/1 ;1 typ.;

or

)1ln(/ ,18...6 typ.;10),1ln(

uc

uuc

Digital image processing Chapter 3. Image sampling and quantization

Page 33: Digital image processing           Chapter 3.  Image sampling and quantization

Examples of contrast quantization:

• For c=u1/3:

 

Digital image processing Chapter 3. Image sampling and quantization

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

t1=0t2=3.9844 t3=31.875 t4=107.5781 t5=2550

50

100

150

200

250

The transfer function of the contrast quantizer

Decision levels

Re

co

ns

tru

cti

on

le

ve

ls

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

Page 34: Digital image processing           Chapter 3.  Image sampling and quantization

Examples of contrast quantization:

• For the log transform:

 

Digital image processing Chapter 3. Image sampling and quantization

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

t1=0 t2=46.0273 t3=102.2733 t4=171.0068 t5=2550

50

100

150

200

250

The transfer function of the contrast quantizer

Decision levelsR

ec

on

str

uc

tio

n l

ev

els

0 50 100 150 200 250

0

100

200

300

400

500

600

700

800

900

1000

Page 35: Digital image processing           Chapter 3.  Image sampling and quantization

b. Pseudorandom noise quantization (“dither”)

Digital image processing Chapter 3. Image sampling and quantization

Uniform quantization, B=4

Large dither amplitude

Small dither amplitude Prior to dither subtraction

Page 36: Digital image processing           Chapter 3.  Image sampling and quantization

Fig. 13

a. 3 bits quantizer =>visible false contours; 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)

a b c d

Digital image processing Chapter 3. Image sampling and quantization

Page 37: Digital image processing           Chapter 3.  Image sampling and quantization

Halftone images generation

Fig.14 Digital generation of halftone images 

Fig.15 Halftone matrices

Digital image processing Chapter 3. Image sampling and quantization

Demo: http://markschulze.net/halftone/index.html

Page 38: Digital image processing           Chapter 3.  Image sampling and quantization

Fig.3.16

Digital image processing Chapter 3. Image sampling and quantization

Page 39: Digital image processing           Chapter 3.  Image sampling and quantization

 

Color images quantization

Fig.17 Color images quantization

Digital image processing Chapter 3. Image sampling and quantization