0% found this document useful (0 votes)
158 views39 pages

Digital Image Processing: Sampling and Quantization

The document discusses digital image processing concepts including sampling, quantization, and the sampling theorem. Sampling converts a continuous signal to a discrete signal by taking samples at regular intervals. Quantization assigns sampled values to discrete levels. The sampling theorem states that a bandlimited signal can be perfectly reconstructed from samples if the sampling frequency is greater than twice the maximum frequency of the original signal.

Uploaded by

Mukarram Salah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views39 pages

Digital Image Processing: Sampling and Quantization

The document discusses digital image processing concepts including sampling, quantization, and the sampling theorem. Sampling converts a continuous signal to a discrete signal by taking samples at regular intervals. Quantization assigns sampled values to discrete levels. The sampling theorem states that a bandlimited signal can be perfectly reconstructed from samples if the sampling frequency is greater than twice the maximum frequency of the original signal.

Uploaded by

Mukarram Salah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Digital Image Processing

Week 2

Sampling and Quantization


Dr. Lavdie RADA
([email protected])
Illumination and Acquisition Using Sensor Strips
Most of the images in which we are interested are generated by the combination
of an “illumination” source and the reflection or absorption of energy
from that source by the elements of the “scene” being imaged.

Dr. Lavdie Rada


([email protected])
Analog signals -Often the domain and the range of an original signal, denoted x(t) are
modeled as continuous. That is, the time (or spatial) coordinate t is allowed to take on
arbitrary real values (perhaps over some interval) and the value x(t) of the signal itself is
allowed to take on arbitrary real values (perhaps within some interval).
Analog signals are sometimes more appropriate or even necessary. For example, most underlying physical
processes are analog (or at least most conveniently modeled as analog), including the human sensorimotor
systems.

Digital signals — signals which have a discrete (often finite) domain and range.

Digitization consist of Sampling and Quantization.

The process of digitizing the domain is called sampling

The process of digitizing the range is called quantization.


Sampling issues:

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

•How many quantization levels should we choose?


• How should the value of the levels be chosen?
•How should we map the values of the original signal to one of the quantization
levels?

Dr. Lavdie Rada


([email protected])
Dr. Lavdie Rada
([email protected])
Dr. Lavdie Rada
([email protected])
Sampling an analog signal

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.

Dr. Lavdie Rada


([email protected])
Intensity values

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.

© 2002 R. C. Gonzalez & R. E. Woods


a b

(a) Continuous image


projected onto a sensor array.
(b) Result of image sampling
and quantization.

© 2002 R. C. Gonzalez & R. E. Woods


0 0 0 75 75 75 128 128 128 128

0 75 75 75 128 128 128 255 255 255

75 75 75 200 200 200 255 255 255 200

128 128 128 200 200 255 255 200 200 200

128 128 128 255 255 200 200 200 75 75

175 175 175 225 225 225 75 75 75 100

175 175 100 100 100 225 225 75 75 100

75 75 75 35 35 35 0 0 0 35

35 35 35 0 0 0 35 35 35 75

75 75 75 100 100 100 200 200 200 200


Image Reconstruction
Suppose we are given a set of samples x[n] that we know came from some
continuous-time signal x(t). We also assume we know the sampling rate T, so
that we know x(nT) = x[n]. How can we recover x(t) for other values of t?

The problem has many solutions.

Dr. Lavdie Rada


([email protected])
Simple estimates to approximately reconstruct x(t).

Nearest neighborhood results in a


piecewise-constant (staircase-like)

Zero-order-hold interpolation results in


a piecewise-constant reconstruction, but
the discontinuities are at the sample
points instead of between sample points.

Linear interpolation result in continuous


function that just connects the sample
values with straight lines.

Higher order interpolation schemes pass smoother


functions through the samples. Dr. Lavdie Rada
([email protected])
The Sampling Theorem (Shannon Sampling Theorem )
The theorem gives the conditions under which a signal can be exactly
reconstructed from its samples.

A signal that changes rapidly will need to be sampled much faster than a
signal that changes slowly.
.

Consider x(t) = sin(ωt) where the frequency ω


is not too large. Using ideal sampling with
one sample every T seconds the sampling
frequency in Hertz is given by fS = 1/T and in
radians by ωs = 2π/T. If we sample at rate fast
compared to ω, that is if ωs >> ω then we are
in a situation shown in the Figure.

Dr. Lavdie Rada


([email protected])
The Sampling Theorem (Shannon Sampling Theorem )

In case of to slow sampling then we are in


a situation of falling on a sinusoid with a
lower frequency than the original x(t).
This phenomenon is called aliasing, since
one frequency appears to be a different
frequency if the sampling rate is too low.

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 natural way to extend the sinusoids example is to use


frequency domain analysis and the Fourier transform.
A signal x(t) is said to be bandlimited if there is some
frequency ωB < ∞ such that X(ω) = 0 for |ω| > ωB
That is, a signal is bandlimited if there is some maximum
frequency beyond which its Fourier transform is zero.

This maximum frequency ωB is the bandlimit of the signal,


and can also be expressed in Hertz as fB = ωB / 2π

As long as the various sinusoids can be treated


independently, we might guess that for a bandlimited
signal we would be able to reconstruct x(t) exactly if we
sample at a rate above 2ωB.

Dr. Lavdie Rada


([email protected])
Sampling Theorem

A bandlimited signal with maximum frequency ωB can


be perfectly reconstructed from samples if the sampling frequency satisfies
ωS >2ωB (or equivalently, if fS > 2fB).

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.

The Fourier transformation of a sampled signal consists of shifted replicas of


X(ω).

Dr. Lavdie Rada


([email protected])
We can see that if we sample fast enough, the replicas will be nonoverlapping.
Then, in principle we could isolate the one un-shifted copy of X(ω) and take the
inverse Fourier transform to recover x(t). To get non-overlapping replicas, we see
that for a bandlimited signal x(t) with maximum frequency ωB, we will need to
sample faster than the Nyquist rate 2ωB. In this case, we can get rid of the extra
shifted copies of X(ω) by multiplying by rect(ω/(2ωB)) in frequency domain.

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

Dr. Lavdie Rada


([email protected])
2D image Sampling

1024 512 256

128 64 32

Sampling depends on the number of sensors a camera has.


As the number of sensors increases the quality gets better.
imread() – reading an image with different
postfixes

imresize() – resizing an image to any given size

figure – opening a new graphical window

subplot(#of row, # of col, location) – showing


different plots/images in one graphical window

imshow() – displaying an image


im=imread('obelix.jpg');
im=rgb2gray(imread('obelix.jpg'));
im1=imresize(im, [1024 1024]);
im2=imresize(im1, [1024 1024]/2);
im3=imresize(im1, [1024 1024]/4);
im4=imresize(im1, [1024 1024]/8);
im5=imresize(im1, [1024 1024]/16);
im6=imresize(im1, [1024 1024]/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.

 Computers can manipulate a digital image to extract spatial information (by


counting pixels) or intensity information (by averaging intensity values)

Dr. Lavdie Rada


([email protected])
Quantization
Can we capture all the gray levels reflected from the object?

• In difference with ‘Sampling’, where the discretization


is on the space, Quantization corresponds to a
discretization of the intensity values. That is, of the
codomain of the function.
• Quantization makes the range of a signal discrete, so
that the quantized signal takes on only a discrete set of
values.

• Unlike sampling, quantization is generally irreversible


and results in loss of information.

Dr. Lavdie Rada


([email protected])
a b
Intensity values
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.

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.

Dr. Lavdie Rada


([email protected])
Image Quantization
• We can choose the number of discrete
quantization levels.
• The number of quantization levels, L
determine the number of bits per sample, k.

Dr. Lavdie Rada


([email protected])
Image Quantization
Example
The below image is an gray scale image.
Means it is an image with 8 bits per pixel (k=8) and its gray level resolution is 256
(L=256).

Dr. Lavdie Rada


([email protected])
Find the difference between

8 bit image 256x256

and

8 bit image 512x512

What is the difference between a gray image and a color (RGB) image?

How we get videos?

Dr. Lavdie Rada


([email protected])
Dr. Lavdie Rada
([email protected])
© 2002 R. C. Gonzalez & R. E. Woods
Quantization
Quantization makes the range of a signal discrete, so that the quantized signal
takes on only a discrete, usually finite, set of values.

Quantization is generally irreversible and results in loss of information.

One of the basic choices in quantization is the number of discrete quantization


levels to use. The fundamental tradeoff in this choice is the resulting signal
quality versus the amount of data needed to represent each sample.

Dr. Lavdie Rada


([email protected])
Quantization

8-bit 7-bit 6-bit 5-bit

4-bit 3-bit 2-bit 1-bit


Image Quantization
The drawbacks of image quantization process:
• Loss of spatial detail
• False contouring
• Artificial boundaries

Dr. Lavdie Rada


([email protected])
generating figure of slide 11
im=imread('obelix.jpg');
im=rgb2gray(imread('obelix.jpg'));
im1=imresize(im, [1024 1024]);
im2= gray2ind(im1,2^7);
im3= gray2ind(im1,2^6);
im4= gray2ind(im1,2^5);
im5= gray2ind(im1,2^4);
im6= gray2ind(im1,2^3);
im7= gray2ind(im1,2^2);
im8= gray2ind(im1,2^1);
figure;
subplot(2,4,1);imshow(im1,[]);subplot(2,4,2);imshow(im2,[])
subplot(2,4,3);imshow(im3,[]);subplot(2,4,4);imshow(im4,[])
subplot(2,4,5);imshow(im5,[]);subplot(2,4,6);imshow(im6,[])
subplot(2,4,7);imshow(im7,[]);subplot(2,4,8);imshow(im8,[])
Dr. Lavdie Rada
([email protected])
Space discretization

Dr. Lavdie Rada


([email protected])
The first image uses 8 bits (256 different grey values), the second 7 bits (128 different value
the third 6 bits(64 different grey values), and the forth 5 bits(32 different grey values)

Dr. Lavdie Rada


([email protected])
© 2002 R. C. Gonzalez & R. E. Woods
Dr. Lavdie Rada
([email protected])
Summary
 We have looked at:
 What is sampling?
 What is spatial resolution?
 What is quantization?
 What is grey-level resolution?

You might also like