Sunteți pe pagina 1din 46

ImageSampling&Quantization

Dr. S.K.Singh
Asso.Prof.,CED,SENSE,VITU,
Vellore,T.N. 632014[India]
Generating a Digital Image
Sampling&Quantization

Imagesampling:referstodiscretizationoftospatialcoordinates(x, y)
Graylevelquantization:referstodiscretizationtheamplitude.

Spatialresolution/imageresolution:pixelsizeornumberofpixels
How to choose the spatial resolution: Nyquist Rate

Originalimage
Sampledimage

1mm
2mm

Nodetailislost!
Minimum NyquistRate:
Spatialresolution
Period Spatial resolution must be less or equal
(samplingrate)
half of the minimum period of the image
or sampling frequency must be greater or
=Samplinglocations
Equal twice of the maximum frequency.
Storage
Ifb =no.ofbitsrequiredtostoreadigitalimage
then,
b N M k

2
no. of bits/pixel
No.ofintensity/gray levels=
i.e. L 2k

IfM = N then, b N 2 k M 2 k

Ex: IfM = N = 128 and L = 64 (k = 6) then,


b N 2 k M 2 k 1282 6 98,304
Storage
Different versions (images) of the same object can
be generated by:
VaryingN,M numbers
Varyingk (numberofbits)
Varyingboth
Exampleofsampling
Blockiness :affectspatialresolution/details

256256
6464
3232
1616
Exampleofquantization
Falsecontouring:affectintensity

8 bits/pixel
4 bits/pixel
2bits/pixel 1bit/pixel
TwoDimensionalSamplingTheory
BandLimitedImages:

Fig.:FTofaBandlimitedFunctionandit'sRoS
y



x

y

x

Fig. a : 2D Sampling Grid

Comb/Shahfunction:

comb x, y; x, y x mx, y ny
m n
Original image Original image spectrum 3D Original image spectrum 2D

2-D rectangular sampling grid


Sampled image spectrum 3D Sampled image spectrum 2D
Thesampledimage,

f s x, y f x, y comb x, y; x, y

f mx, ny x mx, y my
m n

TheFTofCombfunction,
COMB u, v comb x, y; x, y

u xs v ys u ku
k l
xs , v lv ys

1 1
u xs v ys comb u , v; ,
x y
1 1
where, u xs , v ys
x y

Now,FTofthesampledimage,

Fs u , v F u, v COMB u , v

u xs v ys F u, v u ku
k l
xs , v lv ys

u xs v ys F u ku
k l
xs , v lv ys

i.e.,FTofthesampledimageiswithinascalefactor,aperiodic
ReplicationoftheFTofthei/pimageonagridwhosespacingis
uxs , vys .
Reconstruction:
u xs 2u x0 , v ys 2v y0 ; Nyquist rates

i.e.,samplingfrequenciesaregreaterthan,twicethebandwidth.

Or,equivalently,
1 1
x , y ; Nyquist intervals
2u x0 2v y0

then, , canberecoveredbyaLPF withfrequencyresponse

1
u ,v ; u, v
H u , v xs ys
0 ; otherwise


where,isanyregionwhoseboundaryiscontainedwithin
1 2
theannularringbetweentherectanglesand.

F u, v H u, v Fs u, v
F u, v

i.e.,originalcontinuoussignalcanbeexactlyrecoveredbylowpass
filteringthesampledimage.

F 1 u, v f x, y
AliasingandFoldoverFrequencies:
If u xs 2u x0 , v ys 2v y0
or,
1 1
x , y
2u x0 2v y0
Aliasing

u xs v ys
If u , v
2 2
Foldover Freqs.
AliasingandFoldoverFrequencies:

TheMoire effect

Jaggedboundaries
TheMoire Pattern
StatementofSamplingTheorem:
Any bandlimited image , whose RoS is bounded and
sampled uniformly on a rectangular grid with spacing , ,
can be recovered without error from its samples ,
provided the sampling rate is greater than the Nyquist rate,
that is,
1 1
u xs 2u x0 , v ys 2v y0
x y

Moreover, the reconstructed image can be given by the


interpolation formula
sin xu m sin yv ys n
f x, y
m n
f mx, ny xs

xu xs m yv ys n

1Dsinc function 2Dsinc function
Nonrectangularsamplinggrids.Interlacedsamplinggrids
n
v
1/2
F(u,v)=1 n

1 2
2
u
1
-1/2 1/2 1 2 2

-1 0 1 1 2 3 m -2 -1 0 1 2 m
-1/2

a)Imagespectrum b) Rectangular grid G1 c) Interlaced grid G2

Interlacedsampling
v v
1

x x

-1 0 1 u
x x u

d) The spectrum using G1 e) The spectrum using G 2


Example: Animagedescribedbyafunction , 2 2 3 4 is
sampledsuchthat 0.2.Givetheexpressionforthe
reconstructedImage.
Solution: TheFTof , is, , 3, 4 3, 4 .
whichisclearlybandlimitedsince, , 0 for 3, 4.
Hence, 3, 4.Also, 10.2 5,whichisless
than2 and2 .Thesampledspectrumis,

, 25 3 5 , 4 5 3 5 , 4 5

Let,theLPFhavearectangularRoS withcutofffrequenciesathalfthe
samplingfrequencies,thatis,
125 , 2.5 2.5, 2.5 2.5
,
0, otherwise
Now,theFTofthereconstructedimageis,
, , , 2, 1 2, 1
whichgivesthereconstructedimageas,
, 2 2 2
Thisshowsthatanyfrequencycomponentintheinputimagethatis
above 2 , 2 by , isreproduced(aliased)asa
frequencycomponentat 2 , 2 .
ImageQuantization
f x, y u m, n u m, n Digital
Sampler Quantizer
Input Image Computer
Fig.:Digitization

Continuous Tone Image Sampled Image


Sampled & Quantized Image

Digital u m, n D to A u m, n
Display
Computer Converter
Fig.:Display
Quantizer transfer function
u

Quantizer
rL Output
u Quantizer u
rk

u
t1 t2 tk tL 1

Quantizer
r2 Error

r1
Uniform Quantizer transfer function
u
I/p brightnessrange: u lmin ; Lmax

ReconstructionLevels
ReconstructionLevels: Lb rL
b
where,no.ofbitsofthequantiser
rk

DecisionLevels: t1 lmin ; t L 1 Lmax

tk tk 1 tk 1 tk constant q r1
u
t1 tk tL 1
t L 1 t1 L l
q , t k t k 1 q q max min DecisionLevels
L L
tk tk 1 t t q r r rk tk
q
ReconstructionLevels: rk k 1 k 1
2
k k
2

MSQE:GivenimageofsizeMN pixels,u nonquantized,and u quantized
M 1 N 1
1
u m, n u m, n
2

MN m0 n 0
MSQE

1 bits (MSE=1048.9) 2 bits (MSE=219.4) 3 bits (MSE=62.2) 4 bits (MSE=15.3)

5 bits (MSE=3.9) 6 bits (MSE=1.0) 7 bits (MSE=0.2) 8 bits (MSE=0.0)


Example:
Compute the decision levels and reconstruction levels of the 2bit uniform
quantizer for the input range [0; 220] mV.
Lmax lmin q
Solution: q ; tk tk 1 q, 0 k L; rk tk , 0 k L 1
L 2
220 0
Now,inourcase,given l min 0, L max 220, q 55
4
Therefore,thedecisionlevels,
tk tk 1 q t1 t0 55 t1 0 55 55
t2 t1 55 55 55 110, t3 t2 55 110 55 165
t4 t3 55 165 55 220
Similarly,thereconstructionlevels,
rk tk q 2 r0 t0 55 2 r0 0 55 2 27.5
r1 t1 55 2 55 55 2 82.5; r2 t2 55 2 110 55 2 137.5;
r3 t3 55 2 165 55 2 192.5
Alternatively,

220k 55
tk , k 0,1, 2,3, 4; rk tk , k 0,1, 2,3
4 2

u B = 2 => L = 4

r3 192.5
ReconstructionLevels

r2 137.5

r1 82.5

r0 27.5
u
t0 0 t1 55 t2 110 t3 165 t4 220

DecisionLevels
Example:
If the output of an image sensor take values between 0 to 10. If the
samples are quantised uniformly to 256 levels, then estimate the
transition and reconstruction levels.

Solution: 10 k 1
tk , k 1, 2,..., 257;
256
5
rk tk , k 1, 2,..., 256
256
Examplesofuniformquantizationandtheresultingerrors:
u
B = 1 => L = 2
Non-quantized image Quantized image
ReconstructionLevels

r2 192

r1 64
u
t1 0 t2 128 t3 256
DecisionLevels
Quantization error; MSE=36.2
1000

900

800

700

600

500

400

300

200

100

0 50 100 150 200 250

The histogram of the non-quantized image


Examplesofuniformquantizationandtheresultingerrors:
u
B = 2 => L = 4 Non-quantized image Quantized image
r4 224
ReconstructionLevels

r3 160

r2 96

r1 32
u Quantization error; MSE=15
t1 0 t2 64 tk 128 t4 192 t5 256
DecisionLevels

1000

900

800

700

600

500

400

300

200

100

0
The histogram of the
0 50 100 150 200 250
non-quantized image
Examplesofuniformquantizationandtheresultingerrors:
B=3 => L=8; falsecontourspresent
Uniform quantizer transfer function

r8=240
Non-quantized image Quantized image
r7=208

r6=176
Reconstruction levels

r5=144

r4=112

r3=80

r2=48

r1=16

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


Decision levels
1000

900 Quantization error; MSE=7.33


800

700

600

500

400

300

200

100

0 50 100 150 200 250

The histogram of the non-quantized image


Theoptimal(MSE)quantizer (theLloydMaxquantizer)
t L 1

e E[(u u ) 2 ]
t1
(u u ) 2 pu (u ) du

L ti 1
(u ri ) 2 pu (u ) du
i 1 ti


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

t
k 1

2 (u rk ) pu (u ) du 0 ; 1 k L
rk tk

t k 1

rk rk 1 up u (u ) du
tk , rk E u | u t k , t k 1
tk
t k 1
2

tk
pu (u ) du
1
pu (u ) p u (tj ), tj ( t j t j 1 ), t j u t j 1
2
z k t1

A [ p u (u )]1/3 d u whereA t L 1 t1 and


t k 1 t1 ;
t1
k
zk A; 1 k L
t L 1


t1
[ p u (u )]1/3 d u L

wheret L 1 andt1 determineDynamicRange


AofthequantizerarecalledOverloadPoints

ThequantizerMeanSquareDistortion,
3
1 t L1

[ pu (u )] du
1/3

12 L2 t1
p u(u )

u
t1 t2 tj t j+ 1 tL + 1

(u ) 2
exp u
1
pu (u ) exp Gaussian) , or pu (u ) (Laplacian)
2
2
2 2
2

2
2 (variance, - mean)

PropertiesofoptimumMeansquarequantizers
Thequantizer outputisanunbiasedestimateofinputi.e. E u E u

Thequantizer errorisorthogonaltothequantizer outputi.e.,


E u u u 0

quantization error and reconstruction is decorrelated.

Thevarianceof quantizer outputisreducedbythe factor 1 f B


where, f B denotesthemeansquaredistortionoftheBbit
quantizer forunityvarianceinputsi.e.,

2 1 f B u2
u

It is sufficient to design mean square quantizers for zero mean and


unity variance distributions.
Examplesofoptimalquantizationandthequantizationerror:
B=1 => L=2
Functia de transfer a cuantizorului optimal
Non-quantized image Quantized image
Nivelele de reconstructie

r2=153

r1=24

t1=0 t2=89 t3=256


Nivelele de decizie
The quantization error; The evolution of MSE
1000 MSE=19.5 in the optimization, starting
900
from the uniform quantizer
800
38

700 36

600 34

500 32

400 30

300 28

200 26

100 24

22
0
20
0 50 100 150 200 250
18
1 2 3 4 5 6 7 8

The non-quantized image histogram


Examplesofoptimalquantizationandthequantizationerror:
B=2 => L=4
Functia de transfer a cuantizorului optimal Non-quantized image Quantized image

r4=181
Nivelele de reconstructie

r3=156

r2=115

r1=20

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


Nivelele de decizie
The quantization error; The evolution of MSE
1000
MSE=9.6 in the optimization, starting
900

800 from the uniform quantizer


700 15

600
14
500
13
400

300
12

200
11
100

0 10

0 50 100 150 200 250


9

The non-quantized image histogram 1 2 3 4 5 6 7 8 9 10


Examplesofoptimalquantizationandthequantizationerror:
B=3 => L=8
Non-quantized image Quantized image
Functia de transfer a cuantizorului optimal

r8=224

r7=181
Nivelele de reconstructie

r6=165
r5=147

r4=125

r3=101

r2=54

r1=14

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


Nivelele de decizie

1000 The quantization error; The evolution of MSE


900
MSE=5 in the optimization, starting
800
from the uniform quantizer
700
7.5
600
7
500

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
The uniform quantizer = the optimal quantizer for the uniform
grey level distribution:
(alsocalledLinearQuantizer)
pdf of uniform
distribution
1/A
t1 tL+1
t1 tL+1
A

1
, t1 u t L 1
pu (u ) t L 1 t1
0
otherwise

( t k21 t k2 ) t t
rk k 1 k
2( t k 1 t k ) 2

t k 1 t k 1
tk tk tk 1 tk 1 tk constant q
2
tL1 t1 q
q , tk tk 1 q, rk tk
L 2

MSEofUniformOptimalQuantizer,

q/2 2
1 q
du
2
u
q q/2
12

SNRofUniformOptimalQuantizer,

2 B
2 , SNR 10 log 2 2B
6 B dB
u2 10
Compandor
u w y u
f(.) Uniform g(.)
compressor quantizer expander

CompressorExpander
Uniformquantizer proceededandsucceededbynonlinear
transformations
nonlinearfunctionamplifiesorsuppressesparticularranges
Whyusecompandor?
Inputsofsmallervaluessufferhigher%ofdistortionunderuniform
quantization.
Nonlinearityinperceivedluminance:
Smalldifferenceinlowluminanceismorevisible
E.g.visualquantization useluminancetocontrastfunctionascompressor

Overallcompanding systemmayapproximateLloydMaxquantizer
Bytakingp.d.f.intoaccounttodesignthecomressor andexpander
Nonlineartransformationfunctions
TomakeoverallsystemapproximateLloydMaxquantizer
Withoutiterativeprocesstodetermineparameters
Colorimagesquantization

RN T1 T1 RN
Quantizer

GN T2 T2 Color space GN
Color space Quantizer inverse
transformation transformation
T3 T3 BN
BN
Quantizer

S-ar putea să vă placă și