Digital Image Processing: Sampling and Quantization
Digital Image Processing: Sampling and Quantization
Week 2
Digital signals — signals which have a discrete (often finite) domain and range.
•How are the discrete-time samples obtained from the continuous-time signal?
• How can we reconstruct a continuous-time signal from a discrete set of samples?
• Under what conditions can we recover the continuous-time signal exactly?
Quantization issues:
Given an analog signal, as shown in the above figure, the set of samples (equally spaced in
our case) simply pick off the value of the underlying analog signal at the appropriate times.
If we let T denote the time interval between samples, then the times at which we obtain
samples are given by nT where n = ..., −2, −1, 0, 1, 2,....
Thus, the discrete-time (sampled) signal x[n] is related to the continuous-time signal by:
x[n] = x(nT).
It is often convenient to talk about the sampling frequency fs. If one sample is taken every T
seconds, then the sampling frequency is fs = 1/T Hz. The sampling frequency could also be
stated in terms of radians, denoted by ωs. Clearly,
ωs = 2πfs = 2π/T.
Dr. Lavdie Rada
([email protected])
The type of sampling mentioned above is sometimes referred to as “ideal”
sampling. In practice, there are usually two non-ideal effects. One effect is
that the sensor (or digitizer) obtaining the samples can’t pick off a value at a
single time. Instead, some averaging or integration over a small interval
occurs, so that the sample actually represents the average value of the
analog signal in some interval. This is often modeled as a convolution –
namely, we get samples of
y(t) = x(t) ∗ h(t),
so that the sampled signal is y[n] = y(nT). In this case, h(t) represents the
impulse response of the sensor or digitizer.
Note: Sometimes this averaging can be desirable. For example, if the original signal x(t) is changing
particularly rapidly compared to the sampling frequency or is particularly noisy, then obtaining
samples of some averaged signal can actually provide a more useful signal with less variability.
The second non-ideal effect is noise. Whether averaged or not, the actual
sample value obtained will rarely be the exact value of the underlying analog
signal at some time. Noise in the samples is often modeled as adding (usually
small) random values to the samples.
a b
c d
Generating a digital image.
(a) Continuous image.
(b) A scaling line from A to B in
the continuous image, used to
illustrate the concepts of
sampling and quantization.
(c) sampling and quantization
(d) Digital scan line.
128 128 128 200 200 255 255 200 200 200
75 75 75 35 35 35 0 0 0 35
35 35 35 0 0 0 35 35 35 75
A signal that changes rapidly will need to be sampled much faster than a
signal that changes slowly.
.
It turns out that if the original signal has frequency f, then we will be able to exactly
reconstruct the sinusoid if the sampling frequency satisfies fs > 2f, that is, if
we sample at a rate faster than twice the frequency of the sinusoid. If we sample
slower than this rate then we will get aliasing, where the alias frequency is given by
fa = |fs − f|.
Dr. Lavdie Rada
([email protected])
Since we can’t be sure that the true sinusoid is not one of a much higher
frequency and we are not sampling fast enough we should assume from the
outset that the sinusoids under consideration will have a frequency no more
than some maximum frequency fB. Then, as long as we sample faster than 2fB,
we will be able to recover the original sinusoid exactly.
The frequency 2ωB, or 2fB in Hertz, is called the Nyquist rate. Thus, the
sampling theorem can be rephrased as: a bandlimited signal can be perfectly
reconstructed if sampled above its Nyquist rate.
Actually, if the sampling frequency is larger than 2ωB, a rect function with even a slightly larger width could also
be used, as long as the width of the rect is not so large as to include any parts of other replicas. We will also
multiply by T to get X(ω) instead of 1/ T X(ω).
What we have done is to multiply the spectrum of the sampled signal by 1/T rect(ω/(2ωB) in frequency domain
to get X(ω). Then x(t) can be recovered by an inverse Fourier transform. It’s also useful to consider what
operations are done in the time domain in the process of recovering x(t). Recall that multiplication of two signals
in the frequency domain corresponds to a convolution in the time domain – specifically, in this case a convolution
of the sampled signal with the sinc function (since the Fourier transform of a sinc function is the rect function).
As with pure sinusoids, if a signal is sampled too slowly, then aliasing will occur. High frequency components of
the signal will appear as components at some lower frequency. This can also be illustrated nicely in frequency
domain. If sampled too slowly, the replicas of X(ω) overlap and the Fourier transform of the sampled signal is the
sum of these overlapping copies of X(ω). High frequency components alias as lower frequencies and corrupt the
unshifted copy of X(ω). In this figure, the copies are shown individually, with the overlap region simply shaded
more darkly. What actually happens is that these copies add together so that we are unable to know what each
individual copy looks like. Thus we are unable to recover the original X(ω), and hence cannot reconstruct the
original x(t).
128 64 32
figure;imshow(im1)
figure;imshow(im2)
figure;imshow(im3)
figure;imshow(im4)
figure;imshow(im5)
figure;
subplot(2,3,1);imshow(im1);subplot(2,3,2);imshow(im2)
subplot(2,3,3);imshow(im3);subplot(2,3,4);imshow(im4)
subplot(2,3,5);imshow(im5);subplot(2,3,6);imshow(im6)
Review
We defined images as functions in a continuous domain.
To create a digital image, we need to convert the continuous sensed data into
digital form.
We discretise the value by rounding: E.x. If you have the value 9 you round in
different ways :
a) b)
© 2002 R. C. Gonzalez & R. E. Woods
Image Quantization
Definition:
A process of converting an infinite number of possibilities to a
finite number of conditions, rounding the amplitude of
samples to a manageable number of levels.
and
What is the difference between a gray image and a color (RGB) image?