Digital Image Processing: 1 Objective
Digital Image Processing: 1 Objective
Experiment 1&2
1 Objective
Introduction to MATLAB Digital Image Processing Toolbox. To get familiar with some simple
commands related to reading and displaying images using MATLAB.
Let us suppose an image f (x, y) is sampled such that it has M rows and N columns. We
say that this image is of size M x N where x and y can take positive integer values. Although
normally the values of x and y start from (0,0) but in MATLAB they always start from (1,1)
since MATLAB cannot have zero index. The first value in the parenthesis i.e. x represents row
1
while the second value y represents column e.g. notation (1,2) is used to signify the second
sample along the first row. One another difference is that MATLAB image processing toolbox
uses the notation (r, c) instead of (x, y) where r and c represent row and column respectively.
A typical digital image is shown in Figure 1.
A digital image is represented as a matrix in MATLAB. A typical image matrix in MAT-
LAB is shown below.
f (1, 1) f (1, 2) ... f (1, N )
f (2, 1) f (2, 2) ... f (2, N )
. . .
f =
. . .
. . .
f (M, 1) f (M, 2) ... f (M, N )
>> f = imread(’cameraman.tif’);
reads the content of image ’cameraman.tif’ in variable f. The above command reads an image
from the current directory of the MATLAB. The path of the current directory of MATLAB is
normally shown on top of command Window. Figure 2 shows different sections of a MATLAB
2
Current Directory
window.
If you want to read file from a specific directory then you need to give the full path of that
directory with ’filename’ e.g. the following command reads an image from D: drive from
folder named as images.
>> f = imread(’D:\images\cameraman.tif’);
The size of the image can be read using the following command.
>> size(f)
This command gives you the number of rows and columns of the image. You can also use the
following command
>> [M N ] = size(f)
where the number of rows and columns will be saved in M and N respectively. The function
whos can be used to get additional information about an image. For instance
>> whos
will give you details about f e.g. it will tell you the size, number of bytes taken and class of the
image.
3
Q1 : Calculate the number of bits required to represent one intensity level in image ’camera-
man.tif’. (Hint: The total size of an image in bits is MxNxk where k represents the number of
bits required for one intensity level.)
Q2 : Now recalculate the size of image in bytes from k. Does this result tally with the result
given by whos? (Hint: Size in bytes = (MxNxk)/8))
4 Displaying Images
Images are shown in MATLAB by using command imshow e.g.
>> imshow(f)
will display the image read in variable f. The command
Q3 : Find the minimum and maximum intensity value used in image ’cameraman.tif’. (Hint:
The intensity values are stored in ’f’, and minimum and maximum values can be found using
MATLAB built in commands min and max.
Q4 : Now use some value of low and high in command imshow(f, [low high]) based on the
minimum and maximum value found in Q3. You can show many images with different values
of low and high on same figure using command subplot. Use different values of low and high
and see the changes in the image.
If you want to show images in separate figures, the command figure can be used. e.g.
the following commands displays two images in separate figures. If you have more more than
two figures you can use the command figure again.
>> imshow(f)
>> figure
>> imshow(imread(’autumn.tif’))