0% found this document useful (0 votes)
46 views4 pages

Digital Image Processing: 1 Objective

This document provides an introduction to reading and displaying digital images using MATLAB. It defines what a digital image is and how it is represented as a matrix in MATLAB. It describes how to read an image file using imread and display it using imshow. It includes questions about calculating the size of an image file and exploring the effects of manipulating the display range using imshow(image, [low high]).

Uploaded by

Hassan Raja khan
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)
46 views4 pages

Digital Image Processing: 1 Objective

This document provides an introduction to reading and displaying digital images using MATLAB. It defines what a digital image is and how it is represented as a matrix in MATLAB. It describes how to read an image file using imread and display it using imshow. It includes questions about calculating the size of an image file and exploring the effects of manipulating the display range using imshow(image, [low high]).

Uploaded by

Hassan Raja khan
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/ 4

Digital Image Processing

Experiment 1&2

Instructor: Engr. Firdous Kanwal

1 Objective
Introduction to MATLAB Digital Image Processing Toolbox. To get familiar with some simple
commands related to reading and displaying images using MATLAB.

2 Digital Image Representation


A digital image may be defined as a two dimensional function f (x, y), where x and y are
spatial co-ordinates and the value of f at any value of x and y is called the intensity of image
at that point. An image when captured may be continuous with respect to x and y co-ordinates
and also in intensity. Converting such image to digital form means, that the co-ordinates as
well as intensity is digitized. Digitizing the co-ordinates is called sampling, while digitizing
intensity is called quantization. When co-ordinates x and y and intensity values of f are all
finite, discrete quantities, the image is called digital image. In this lab we will use MATLAB
for digital image processing. MATLAB has a special toolbox for dealing with images known
as Image Processing Toolbox.

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 )

3 Reading Images in MATLAB


Images are read in MATLAB using command
>> imread(’filename’)

where ’filename’ is full name of an image file including extension. e.g.

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

Figure 1: A typical digital image

2
Current Directory

Current Folder Work Space

Details about any file Command Window Command History

Figure 2: MATLAB Window

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

>> imshow(f, [low high])


displays all the pixels as black which are less than or equal to low and all values as white
which are greater than or equal to high. All the values in between are displayed as intermediate
intensity values using the default number of levels.

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

You might also like