You are on page 1of 7

# Lab 1

## MATLAB Specics Digital Image

Processing
The objective of this lab is to read a digital image and to access pixels in it for applying dierent arithmetic operations. The functions like: imread(), imwrite(), imshow(), imf inf o(),
imunit8(), imuint16(), mat2gray(), imdouble(), and im2bw() will be discussed in this lab.

1.1

## Basic MATLAB Function Related to a Digital Image

Digital image is a two dimensional array, having nite rows and columns. In MATLAB
it is stored in two dimensional matrices. For example Fig. 1.1 shows pixels in an image.
The top left corner of this array shows the origin (0,0). In MATLAB we have origin
starts from (1,1) because MATLAB addresses rst element in two dimensional matrix by
< matrixname >(1,1).

This digital image can be retrieved into a MATLAB matrix using imread() function. The
imread() loads an image stored on specic location to a 2-D array. Its Syntax is:
F = imread( < f ilename.extension > )
The imwrite() command is used for writing an image to the disk. The syntax imwrite()
command is:
F = imwrite(2 Darray, < f ilename.extension > , ...)
The imshow() function is used for displaying the stored images. The syntax of imshow()
function is:
F = imshow( < f ilename.extension > )
The imf inf o command to collect the statistics about an image in a structure variable. The
output of command is given in Fig. 1.2.

Lab 1

1.2

## Data classes and Image Types

MATLAB and IPT support various data classes for representing pixels values. These data
classes include: double, uint8, uint16, uint32, int8, int15, in32, single, char, and logical. The
rst eight are numeric data classes and the last two are character and logical data classes

## MATLAB Specics Digital Image Processing

Lab 1

respectively. The double data type is most frequently used data type and all numeric computations in MATLAB require quantities represented in it. The uint8 data classes is also
used frequently especially when reading data from storage device, a 8-bit images are the most
common representation found in practice. We will focus mostly on these two data types in
MATLAB. Data type double requires that quantity represented in 8-bytes, uint8 and int8
require 1-byte each, uint16 and int16 require 2-bytes, and uint32, int32, and single, require
4-bytes each. The char data class holds character in Unicode representation. A character
string is merely a 1xn array of characters. A logical array contains only the values 0 and 1,
with each element being stored in memory using one byte per element. Logical array a re
created by using function, logical, or by using relational operations.

1.3

Image Types

In this section we will study the four types of images supported by IPT toolbox.
Intensity images
Binary images
Indexed images
RGB Images

We will initially focus on Intensity images and Binary images because most of the
monochrome image processing operation are carried out using these two image types.

1.3.1

Intensity Images

An intensity image is a data matrix whose values have been scaled to represent intensities.
When the elements of an intensity image are class uint8, or class uint16, they have integer
values in the range [0, 255] and [0,65535], respectively. Values are scaled in the range [0,1]
when double class is used to represent the values in data matrix.

1.3.2

Binary Images

Binary images are logical array of 0s and 1s. Logical array, B, is obtained from numeric array,
A, using logical function.
B = logical(A)%convertingnumericarrayintologicalarray
islogical function is used to test the logical value of, B.
islogical(B) % To check whether B is logical or not

Lab 1

1.4

## Converting between Data Classes and Image Types

It is frequently desired in IPT application to convert between data classes and image types.

1.4.1

## The general syntax for converting between data classes is:

B = data classes name(A)
We are frequently required to convert array A, data class uint8, into double precision (oating
point numbers) array, B, by command B = double(A) for numerical operations. Conversely,
C = uint8(B) is used for converting fractional parts of array C, double, in [0, 255] into uint8
array C.

1.4.2

## Converting between Image Classes and Types

The table in Fig. 1.3 contains necessary functions for converting between image classes and
types. The conversion of 3 x 3 double image into uint8 image is given in Fig. 1.4.

Figure 1.3: Functions for converting between image classes and types.

1.5

## Indexing Rows and Columns in 2-D Image and Image Rotation

As we studied in Sec. 1.1 that a digital image is represented 2-D matrix and its pixels, rows
Individual pixel < matrixname > (row, col)
Complete row < matrixname > (row, :)
Complete column < matrixname > (:, col)
The above array indexing is used in 90o rotation of an image and is shown in Fig. 1.5

Lab 1

## Figure 1.4: Conversion between double and uint8 data classes

Figure 1.5: Original Lena (left) and 90o Degree Rotated Lena (right)

1.6

Practical

## Use these basic concept and perform the following activities:

1.6.1

Activity No.1

Read various image ,having dierent le extensions, stored at work directory and c : mydocmypic
using imread() function and show them using imshow function.

1.6.2

Activity No.2

Use MATLAB help to compress an image, with .jpeg extension, with imwrite() function and
and nd the compression ratio with original image.

Lab 1

1.6.3

## Hint for Activity No.2

Use Fig. 1.2 for nding the sizes of original and compressed image and then divide the size
of original image by the size of compressed image to nd the compression ratio.

1.6.4

Activity No.3

Read an image and rotate it by 180o and 270o , using array indexing. Add the original
image and rotated image using imadd() function. Repeat this activity for imsubtract(),
immultiply(), imabsdif f (), imlincomb(), and imcomplement() functions.

1.6.5

## Hint for Activity No.3

First convert the images into double from gray levels and the apply these function and then
convert it to gray levels using mat2gray() function.

1.6.6

Questions

1. Why we convert gray levels into double before using numeric operations?
2. What is the eect of compression of an image on its quality?