Sampling Quantization
Sampling Quantization
n
ya
hu
.B
.K
M
Image Sampling
Introduction
n
•
ya
In the design and analysis of image sampling and reconstruction
hu
.B
systems, input images are usually regarded as deterministic fields.
.K
• M
However, in some situations, it is advantageous to consider the
input to an image processing system, as a sample of a two-
dimensional random process.
g(t)
sampled signal
n
ya
hu
.B
t
.K
M
s(t) t
Train of one-dimensional
Dirac delta functions
– Comb function
n
ya
1 1 + − j 2i t /Ts j 2i t /Ts
hu
g (t ) = comb(t ).g (t ) = g (t ) + g (t ) e [ +e ]
.B
.K
i =1
M
Ts Ts
and its Fourier transform is
+ +
G ( f ) = f s G( f ) + f s i=1[G( f + if s ) + G( f − if s )] = f s i =−
G ( f − if s )
G(f)
G(0)
f
-B 0 B
n
ya
(a) Spectrum of a band limited (base-band) 1-D signal
hu
.B
.K
M G(f)
2B.G(0)
f
-2fs -fs 0 fs 2fs
n
ya
hu
+ fs / 2 + f /2
.B
s +
1 1
.K
df = f s G ( f )e j 2nf / f s df = G ( f )e j 2nfTs df = g (nTs )
j 2nf / f s
Cn =
M
G ( f )e
fs − fs / 2
fs − fs / 2 −
Thus, we see that the sample values are itself the Fourier coefficients.
• That means, if the input is band-limited to B Hz, the minimum sampling rate required for no
overlapping is fs,min = 2B Hz.
n
•
ya
This minimum sampling rate is called the Nyquist rate or Nyquist frequency.
hu
.B
Reciprocal of Nyquist rate is called Nyquist interval.
.K
M
• Sampling at a rate greater than the Nyquist rate (over-sampling) leaves room for guard-
band.
• According to “Sampling Theorem”, if the sampled waveform is passed through an ideal LPF
with cut-off frequency equal to half the sampling frequency or equal to B, then the original
signal g(t) can be faithfully recovered (scaled by fs ) if fs ≥ 2B.
• Since practically it is not possible to have ideal LPF (sharp cut-off), over-sampling is
recommended for proper reconstruction.
• Sampling at a rate less than Nyquist rate (under-sampling) leads to aliasing error.
Sampling Theorem and signal reconstruction
• Ideal LPF with cut-off = fs / 2 is given as sin f s t
H ( f ) = rect ( f / f s ) h(t ) = f s
f s t
• Therefore, when the sampled waveform is passed through the filter the output is given as
+
G ( f ) H ( f ) = f S G ( f ) g (t ) * h(t ) = g (t ) = g (nTs )δ(t − nTs ) * h(t ) = g[n]h(t − nTS )
n =− n =−
• The convolution on the RHS is the inverse Fourier transform of the LHS which is equal to fs.g(t).
Accordingly, we now see
+
sin f s (t − nTs ) +
sin f s (t − nTs ) +
RHS = g (nTs ) f s g (t ) = g (nTs ) = g[n] sinc( f st − n)
n
ya
− −
hu
n =− f (t nT ) n =− f (t nT ) n =−
.B
s s s s
.K
M
• NOTE: The filter output is scaled by fs. So if we wish to obtain the original signal without any scaling, the
reconstruction filter should be scaled by 1/ fs.
• The sampling theorem, hence, may be stated as “If the highest frequency contained in an analog signal g(t)
is B and the signal is sampled at a rate fs ≥ 2B then g(t) can be recovered from its sample values using the
interpolation function
1
f | f | f s / 2
sin f s t s
h (t ) = = sinc f s t H ( f ) =
f s t 0 otherwise
where the interpolation function is implemented by an an ideal LPF with cut-off equal to fs / 2 and scaled by
1/ fs → such filter is called reconstruction filter .
.
M
.K
.B
hu
ya
n
Aliasing
• If the sampling rate is less than the Nyquist rate (under-
sampling) the spectral components overlap, resulting in
distortion for high frequency components of the signal.
n
•
ya
So, there is distortion in frequency components due to
hu
2B.G(0)
spectral overlapping in case of under-sampling and the
.B
phenomenon of high frequency components getting
.K
M
translated to lower frequency is called aliasing.
F(u, v) v
v0
n
ya
hu
.B
.K
M
u
-u0 u0
u
u0
v -v0 -v0
(a) Spectrum of a band limited 2-D signal (b) Its region of support
M
.K
.B
hu
ya
n
Sampling 2-D Deterministic Fields
n
ya
hu
.B
.K
f (mx, ny) ( x − mx, y − ny)
M
=
m=− n = − y
and the spectrum of the sampled image is Sampling grid
F (u, v) = us vs F (u − kus , v − lvs )
k =− l =−
x
where us = 1
x
vs = 1
y
f ( x, y ) = F (u, v)
x y
Spectrum of the 2-D sampled signal
v
1/x
vs
vs-v0
1/y
R1
n
ya
hu
0 2v0
.B
.K
M
R2
2u0
u
u0
us-u0
us
Reconstruction of the Image from its Samples
• If the x,y sampling frequencies are greater than twice the bandwidths, that is,
n
ya
hu
.B
.K
then F(u,v) can be recovered by a low-pass filter.
M 1 ,
• The filter frequency response is,
(u , v ) R
(ideal 2D LPF scaled by 1/(usvs)
H (u, v) = (usvs )
reconstruction filter) 0, otherwise
where R is any region whose boundary is contained within the annular ring between the
rectangles R1 and R2 shown in the Figure, i.e.:
~
F (u, v) H (u, v) F (u, v) = F (u, v)
That is, the original continuous image can be recovered exactly by low-pass filtering the
sampled image.
Nyquist Rate
• The lower bounds on the sampling rates, that is 2u0, 2v0 are the Nyquist
rates or the Nyquist frequencies.
n
ya
hu
.B
.K
then the periodic replication of F(u,v) will overlap, resulting in a distorted
M
spectrum Fs(u,v). In this case, F(u,v) cannot be recovered from Fs(u,v).
• When we view a digital image, our eyes act as the reconstruction filter
(the eye is essentially an LPF).
vs
vs/2
n
ya
2v0
hu
0
.B
.K
M us/2
2u0
u
0 us
n
ya
hu
.B
.K
M
• If R = − 1 u , 1 u − 1 v , 1 v
2
s s
2
s
2
s
2
i.e., rectangle centered at the origin, then the impulse response
of the low-pass filter is,
h( x, y) = sinc( xus )sinc( yvs )
• Hence, ~
F (u , v) H (u , v).F (u, v)
n
ya
f ( x , y ) h ( x , y ) * f ( x, y )
hu
.B
.K
M
~
f ( x, y ) f (mx, ny)sinc( xus − m)sinc( yvs − n)
m ,n = −
~
f ( x , y ) = f ( x, y ) if x 1
2u 0
and y 1
2v 0
• Then the reconstructed image is:
~
f ( x, y ) = f (mx, ny ) sin( xus − m ) sin( yvs − m )
( xu −m ) ( yv −m )
s s
m = − n = −
Image reconstruction
• Two-dimensional interpolation can be performed by successive
interpolation along rows and columns of the image.
n
the required ideal 2D-LPF.
ya
hu
.B
.K
M
• The zero-order- and first-order-hold filters give piecewise constant and
linear interpolations, respectively, between the samples.
• Higher order holds can give quadratic (n=2) and cubic spline (n=3)
interpolation.
• With proper coordinate scaling, the nth-order hold can converge to the
Gaussian function as n .
• The display spot of a CRT is circular and can be modeled by a
Gaussian function whose variance controls its spread (practical
approximation to the required interpolation function).
Image Quantization
Introduction to quantization and quantizer
Quantization involves representing the sampled data by a finite number of levels
based on some criteria such as minimization of the quantizer distortion, which must
be meaningful. Quantizer design includes input (decision) levels and output
(reconstruction) levels as well as number of levels. The decision can be enhanced by
psychovisual or psychoacoustic perception. Quantizers can be classified as
n
ya
memoryless (assumes each sample is quantized independently) or with memory
hu
.B
.K
(takes into account previous sample) . We limit our discussion to memoryless
M
quantizers. Alternative classification of quantisers is based on uniform or non-
uniform quantization. They are defined as follows.
Non-uniform quantizers
Uniform quantizers
They are completely defined by (1) the
number of levels it has (2) its step size and The Step sizes are not constant. Hence
whether it is midriser or midtreader. We will non-uniform quantization is specified by
consider only symmetric quantizers i.e. the input and output levels in the 1st and 3rd
input and output levels in the 3 rd quadrant quandrants
are negative of those in 1st quandrant.
• A quantizer is a “staircase function” t = Q(s) that
maps continuous input sample values s into a
discrete and finite set of output values t
(reconstruction values).
n
ya
hu
Zero is the decision level between the quantization
.B
intervals “1” and “−1” by default. So, there is no
.K
M
reconstruction level corresponding to “0” and
consequently all points in the digitized signal are
non-zero. This type is called mid-rise quantizer, as
shown in fig.
Uniform Quantizers
Step size constant in both cases
n
ya
hu
.B
.K
M
Non-Uniform quantizer
M
.K
.B
hu
ya
n
Image quantization
F = f | f min f f max
n
reconstruction level is selected per interval. The set of reconstruction values:
ya
hu
.B
Fˆ = fˆi | i = 0, 1,.....,L − 1
.K
M
• Decision levels for the kth interval: fk and fk+1, i.e., the interval is from fk to fk+1.
Accordingly, we should have f0 = fmin and fL = fmax
n
ya
hu
i = 0 fi
.B
.K
➢ Overload noise – If the dynamic range of the input signal is greater
M
than the range for which the quantizer is designed, i.e., f0 > fmin and
fL < fmax, then a sample falling in the interval from fmin to f0 or fL to fmax
is mapped to its nearest quantization interval “0” or “L − 1”
respectively. This contributes to the overload noise.
➢ Total quantization noise; q2 = E (F - F)ˆ 2
= g2 + o2
f0 f max
f min fL
Quantization noise
We observe that
n
ya
increases. Hence, overload noise decreases but granular noise
hu
.B
increases to some extent.
.K
M
• Overload noise can be reduced, even may be zero, by appropriate
designing of the quantizer.
n
ya
hu
.B
.K
M Granular noise
Slope overload distortion: This type of distortion is due to the use of a step size
delta that is too small to follow portions of the waveform that have a steep
slope. It can be reduced by increasing the step size.
Granular noise: This results from using a step size that is too large in parts of
the waveform having a small slope. Granular noise can be reduced by
decreasing the step size.
Types of quantizer – uniform quantizer
• Uniform quantizer – the quantization intervals are same for all k.
➢ This type of quantizer is generally used when the pdf of the random variable f is constant
over the finite range fmin to fmax, i.e., pdf is given as
pF ( f ) = 1
( f max − f min )
❖ Interval lengths or step size: ( f max − f min )
=
n
ya
L
hu
.B
.K
❖
M
Decision levels:
fk = k
❖ Reconstruction levels:
( f k + f k +1 ) 1
fˆk = = k +
2 2
❖ The spacing between successive reconstruction levels is same as the interval length Δ.
❖ For sufficiently small Δ we may assume granular noise is uniformly distributed over the range
−Δ/2 to +Δ/2.
Non uniform quantizer
• If the input values f are not uniformly distributed, the
“uniform quantizer” with equally spaced quantization
(reconstruction/decision) levels is not a good choice.
n
ya
hu
.B
non-uniform, it is required to construct a quantizer so
.K
M
that distortion is minimum.
n
ya
is no overload noise. The quantization noise is solely
hu
.B
due to granular noise. So, it is required to minimize
.K
M
the expression for granular noise given before.
➢ For a given set of reconstruction levels, the optimal choice for all the decision levels, except the
extreme ones, are the mid-points between each pair of consecutive reconstruction levels:
q2
=0
f k
n
ya
hu
L−1 fi +1
( f − fˆi )2 pF ( f )df = 0
.B
f k i =0 fi
.K
M
fk ˆ )2 p ( f )df +
f k +1 (check this yourself).
− ( f − fˆk ) pF ( f )df = 0
2
f k fk −1
( f f k −1 F
f k fk
1
f k ,opt = ( fˆk −1 + fˆk )
2
Input level is average of two adjacent output levels
➢ For a given set of decision levels, the optimal choice for all the reconstruction levels are the
centroids in each interval between each pair of consecutive decision levels:
f k +1
fpF ( f )df
q2
= 0 fˆk ,opt =
fk
ˆ
f f k +1
pF ( f )df
k
fk
n
levels), the best quantizer is a nearest neighbor
ya
hu
.B
mapper.
.K
M
❑For a given quantizer (set of decision levels), the
best reproduction for all the inputs contained in a
given interval is the centroid of that interval.
Designing Lloyd-Max quantizer
• The two equations are coupled and cannot be solved analytically independent of
each other.
n
ya
❖ Repeat the above two steps iteratively until the algorithm converges to some final
hu
.B
solution (when there is no more change in the levels).
.K
M
• However, tables of numerical solutions for different standard probability
distributions and quantization levels L are available.
vector ri = [r1 , r2 ........rN ]T where ri is chosen from L possible reconstruction quantization levels.
n
ya
hu
fˆ = VQ( f ) = ri , f Ci
.B
i.e where ri for 1 i L denotes L reconstruction levels and Ci is called
.K
M
the i th cell. If f is in cell , is mapped to ri .
An example of vector quantization when N=2 and L=9. The filled in dots are reconstruction levels and solid lines are cell
boundaries.
Vector Quantization
• Blocks:
– A sequence of audio.
– A block of image pixels.
Formally: vector example: (0.2, 0.3, 0.5, 0.1)
• A vector quantizer maps k-dimensional vectors in the
vector space Rk into a finite set of vectors Y = {yi: i = 1, 2,
n
ya
hu
..., N}. Each vector yi is called a code vector or a
.B
.K
M
codeword. and the set of all the codewords is called a
codebook. Associated with each codeword, yi, is a nearest
neighbor region called Voronoi region, and it is defined by:
n
ya
hu
.B
.K
M
n
ya
hu
.B
.K
M