Dip 05
Dip 05
Experiment 5
Implement the effects of changing the Gray level Resolution, Spatial
Resolution via Pixel replication, Nearest Neighbor interpolation
Image resolution
Image resolution describes the detail an image holds. The term applies to digital images, film images,
and other types of images. Higher resolution means more image detail.
The term resolution is often used for a pixel count in digital imaging, even though American,
Japanese, and international standards specify that it should not be so used, at least in the digital
camera field. An image of N pixels high by M pixels wide can have any resolution less than N
lines per picture height, or N TV lines. But when the pixel counts are referred to as resolution,
the convention is to describe the pixel resolution with the set of two positive integer numbers,
where the first number is the number of pixel columns (width) and the second is the number of
pixel rows (height), for example as 640 by 480. Another popular convention is to cite resolution
as the total number of pixels in the image, typically given as number of megapixels, which can be
calculated by multiplying pixel columns by pixel rows and dividing by one million.
Below is an illustration of how the same image might appear at different pixel resolutions, if the
pixels were poorly rendered as sharp squares (normally, a smooth image reconstruction from
pixels would be preferred, but for illustration of pixels, the sharp squares make the point better).
An image that is 2048 pixels in width and 1536 pixels in height has a total of 2048×1536 =
3,145,728 pixels or 3.1 megapixels. One could refer to it as 2048 by 1536 or a 3.1-megapixel
image.
Sampling
Sampling is the principal factor determining the spatial resolution of an image. Basically spatial
resolution is the smallest noticeable detail in an image.
As an example suppose we construct a chart with vertical lines of width W, and with space
between the lines also having width W. A line-pair consists of one such line and its adjacent
space.
Thus width of line pair is and there are line-pairs per unit distance. A widely used
definition of resolution is simply the smallest number of distinct line pairs per unit distance; for
example 100 line pairs/mm.
We have considerable preference regarding the number of Samples used to generate a digital
image. But this is not true for the number of gray levels. Due to hardware constraints, the
number of gray levels is usually an integer power of two. The most common value is 8 bits. It can
vary depending on application. When an actual measure of physical resolution relating pixels
and level of detail they resolve in the original scene are not necessary, it is not uncommon to
refer to an Llevel digital image of size as having a spatial resolution of pixels and a
gray level resolution of L levels.
The quality of an image depends on both spatial resolution and gray level resolution. The quality
of a gray-level image is significantly affected by its gray-level resolution. If you increase the
number of bits per pixel for image then it has a great effect in improving the quality of gray-level
images because higher number of gray levels would give a smooth transition along the details of
the image while decreasing the number of bits per pixel shows false boundaries in the image an
effect known as “False Contouring”
The figure below shows gray levels using 8 bits and 3 bits.
In the top section of the figure there are 256 levels of gray (8-bits) while in the bottom section
there are only 8 levels (3-bits) of gray.In this experiment, the gray level resolution of an image is
to be reduced from 256 to 2, each time by a factor of 2 (equivalently, reducing the number of bits
per pixel from 8 to 1).The change of the image quality and the false contouring effect are to be
observed.
In MATLAB, this can be performed by reducing the number of gray levels that are required to
display the image using a smaller number of rows in the colormap matrix. All of this will be
performed while keeping a constant spatial resolution for the image (256 X 256).
Figure 1 Figure 2
Zooming (up scaling, resizing upward) can be achieved by the following techniques ::
For any zooming approach we have to create an imaginary grid of the size which is required over
the original image. In that case we will have a scenario where we have new locations void of
pixel values, now we have to insert new values on these empty locations.
In Nearest neighbor interpolation we look for the closest pixel in the original image and assign its
gray level to new pixel in the grid. When finished with all points in the grid, we can simply expand
it to the originally specified size to obtain the zoomed image.
Assume
• Image I1 has size M1xN1
• Image I2 has size M2xN2
Then
• x=Cv
• y = Cy w
Algorithm:
Read desired image and get its dimensions.
Traverse through the each element of the zoomed image matrix and copy the relevant value
from original image.
Example :
The pictorial representation depicts that a 3x3 matrix is interpolated to 6x6 matrix. The values in
the interpolated matrix are taken from the input matrix (i.e) no new value is added.
Example 4:
%3x3 Matrix
A = zeros(3,3);
A(:)=[10,2,9,4,18,14,22,7,25];
display(A); %Before Interpolation
C = imresize(A,[6,6],'nearest');
display(C); %After Interpolation
EXPLANATION:
The result as shown in the pictorial representation can be achieved using the MATLAB function
‘imresize’
Example 5:
% Read image into the workspace.
I = imread('rice.png');
% Resize the image, specifying scale factor and the interpolation method.
J = imresize(I, 0.5, 'nearest');
% Display the original and the resized image.
figure imshow(I) title('Original Image')
figure imshow(J) title('Resized Image Using
Nearest Neighbor')
2-Pixel Replication
Pixel replication is applicable when we want to increase the size of an image an integer number of
times. For example to double the size of an image we can duplicate each column, this doubles the size
of image in horizontal direction. Then we duplicate each row of the enlarged image to double the size
in the vertical direction.
Example 6: Enlarge the image 3 times with pixel replication
a =imread('cameraman.tif');
c =size(a);
for i = 1:1:c(1)
b=0;
for j = 1:1:c(2)
for k = 1:1:3
bbb(i,j+b)=a(i,j);
b=b+1;
end
b=b-1;
end
end
cc=size(bbb);
for i = 1:1:cc(2)
b=0;
for j = 1:1:cc(1)
for k = 1:1:3
bb(j+b,i)=bbb(j,i);
b=b+1;
end
b=b-1;
end
end
size(bb);
figure imshow(a)
figure imshow(bb)
LAB TASKS
TASK 1: Use nearest neighbour interpolation to get the resultant matrix.(implement with both
code and matlab builtin function “imresize”)
Input matrix
3 9
7 12
Resultant matrix
3 3 9 9
3 3 9 9
7 7 12 12
7 7 12 12
TASK 2
Take any built-in image as an input and Reduce its spatial resolution to ½ and 1/4 of the
original image .
I. Display the original image,
II. Displqay ½ of original image
III. Display 1/4 of original image .