University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Experiment No. 3
Image Sampling and Quantization:
Object:
The purpose of this experiment is to be familiar with the concept of image sampling and quantization.
Introduction:
Sampling of a signal is a process of creating a discrete signal from the continuous one, in a way that the
values (samples) are taken only in the certain places (or with certain time steps) from the original continuous
signal.
Nowadays, digital images are dense sampled signals while many of the image processing algorithm need to
deal with images sampled at smaller frequency (sample rate), this process is called subsampling because it
denotes taking a subset from the existing samples. If we want to subsample an image, we simply take every
N-the pixel.
Quantization is the process that involves representing the sampled signal by a finite number of levels based
on some criteria such as minimization of the quantizer distortion, which must be meaningful or hardware
considerations.
Procedure:
1. Image down sampling: Matlab provides a direct function to down sample signals, with the ability to
decide the down sampling factor.
y = downsample(x,n) where:
x: is the vector to be down sample, n:
is the down sampling factor.
Example 1:
In this example the original image is down sampled by factor 4
Io = imread('cameraman.jpg'); if(size(Io,3)==3)
Io=rgb2gray(Io); end subplot(1, 2, 1), imshow(Io),
title('Original image')
d_f = 4; % downsampling factor
(1 - 3)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
d_Io = downsample(Io,d_f); % downsample in row direction
d_Io = downsample(d_Io',d_f)'; % downsample in column direction
subplot(1, 2, 2), imshow(d_Io), title('downsampled image')
2. Image quantization: the Matlab function that used for image quantization is imquantize.
quant_A = imquantize(A,n)
where:
A: is the original image, n:
is the quantization levels.
Example 2:
In this example the original image is uniformly quantized into 8 levels.
Io = imread('peppers.png'); if(size(Io,3)==3) Io=rgb2gray(Io); end
subplot(1, 2, 1), imshow(Io), title('Original image')
n_q = 8; % specify the number of quantization levels
(2 - 3)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
dd = linspace(256/n_q,256,n_q); % specify the quantization levels
I_q = imquantize(Io,dd); subplot(1, 2, 2), imshow(I_q, []), title('quantized
image')
Exercise: do the following:
1. Down sample the bigben.png image by factors 2, 8 and 16.
2. Quantize uniformly the onion.png image to 16, 4 and 2 levels.
3. How to down sample color images?
4. How to quantize color images?
(3 - 3)