0% found this document useful (0 votes)
5 views7 pages

Exp 01

This lab manual outlines an image processing experiment using MATLAB, focusing on reading, displaying, and converting images. Students will learn to utilize various MATLAB functions for image manipulation, including converting color images to grayscale and binary formats. The manual also includes a section for students to document their code, input/output, observations, conclusions, and questions related to real-life applications of image processing.

Uploaded by

sachinchavan68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Exp 01

This lab manual outlines an image processing experiment using MATLAB, focusing on reading, displaying, and converting images. Students will learn to utilize various MATLAB functions for image manipulation, including converting color images to grayscale and binary formats. The manual also includes a section for students to document their code, input/output, observations, conclusions, and questions related to real-life applications of image processing.

Uploaded by

sachinchavan68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

LAB Manual

PART A
(PART A : TO BE REFFERED BY STUDENTS)

Experiment No. 01
A.1 Aim:
Apply image processing algorithms on the test image to obtain new image.
i. Open, show and save images using different techniques.
ii. To observe the effect of different gray level images on their corresponding image matrix
iii. Image conversion (Color to Gray, Gray to Binary).
iv. Covert image formats.

A.2 Prerequisite:
1. Understanding of fundamental programming functions/commands and environment of
Matlab (Refer the Matlab manual),
2. Availability of Soft copy of your Photograph for experiment.

A.3 Outcome:
After successful completion of this experiment students will be able to

1. Use following Matlab functions/structures for programming.


clc, clear all, ‘; ’ operator, Imread( ), Imwrite( ), Imshow( ), size( ),
resize( )
2. Explore the Matlab workspace and understand the matrix
representation of an Image

A.4 Theory:

Introduction of MATLAB:

MatLab is a programming language for mathematical operations It provides


development environment for mathematical programming. It is very much
useful for matrix manipulation hence it is good choice for signal processing
and image processing applications.
Some commands and programs in MATLAB:

[1] Declaring matrices: In Matlab, there is no need to declare variables;


new variables are simply introduced as they are required.

>>A = [1 2 3; 4 5 6; 7 8 9]

The above MATLAB command declares following matrix:

Keep following things in mind while declaring variables/matrices:


 No spaces
 Don’t start with a number
 Variable names are case sensitive

[2] Populating matrix elements with zeros:


Matlab also provides a number of functions which can be used to populate a
new matrix with particular values. For example to make a matrix full of
zeroes we can use the function zeros(m, n) which creates an m*n matrix of
zeros as follows:

>>B = zeros(3,3)

[2] Knowing size of matrix:


Syntax:
[rows, cols] = size(A);
This function gives size of matrix Above command gives result: rows=3,
cols=3
[3] Reading Image file : We can use following command to read image
file:

myImage=imread(‘File name with path’)


If name of the image file is test.bmp and if it is in /home/chv folder above
commands can be written as:
myImage=imread(‘/home/chv/test.bmp’)
The image filename can be given as a full file path or as a file path relative to
the Matlab current directory. The current directory can be changed from the
main Matlab interface window or by cd (change directory command). The
supported file formats include ‘bmp’, ‘gif’, ‘jpg’ and ‘png’.
After giving above command image data is available in myImage variable.
You can use any variable name.

[4] Displaying image : After reading image data using above function, we
can display images in Matlab using imshow function. This function simply
takes the array storing the image values as its only parameter.
Syntax:
imshow(<variable name>)
Example:
imshow(myImage);

[5] Knowing size of image in pixels:


Size of the image in pixels can be found out by following command:
[Rows, Cols] = size(myImage)

[6] Image resizing: Image resizing can be done by following command:


imresize(Image,{Parameters});
For example:
Consider that we read the image in variable myImage using imread function
than we can resize the image stored in this variable by following command
imresize(myImage,[256,256],’nearest’);
This command will convert image of any size into image of 256x256 using
nearest neighbor technique.
[7] Displaying multiple images in single figure.
1. To display multiple images simultaneously we can use function
figure(figure_number).
Figure function will create new figure window for each image to be displayed.
2. To display multiple images in single window we can use function subplot(m,n,p).
where m is for number of rows in which figure window is divided, n is number of
columns and p indicates section number.
For example if we write subplot(2,2,1) will divide the figure window in four
subsections and image will be plotted in first section.

1 2
3 4
[8] Write image to file.
Generated image can be written to image file using function
imwrite(‘filename.extension’).

[9] Converting Color image into Grayscale image: Color image can be
converted into Grayscale image by Matlab command rgb2gray.
Example:
myGrayImage=rgb2gray(myImage)
[10] Converting gray scale image into Black and white image:
grayscale image can be converted into Black-n-White image by Matlab
command im2bw.
Example:
myBWImage=im2bw(myGrayImage)

[11] Flow control in MATLAB: If statements are simply used to make


decisions in Matlab
Syntax:

if <condition> then
<do some work>
else
<do some other work>
end

[12] Loops in MATLAB: There is for loop and while loop in MATLAB.

While loop
While loop repeat a piece of work as long as a condition holds true. The while
loop in Matlab uses the following syntax:
while <condition>
<perform some work repeatedly…>
end

For loop in MATLAB is very popular for image processing because it is


particularly useful for iterating through the members of a matrix.
The MATLAB for loop uses the following syntax:

for index = <start>:<finish>


<Perform some work…>
end

A.5 Procedure/Algorithm:
A.5.1 TASK 1 & 2:

1. Create new file in MATLAB


2. Write a program to Read Image file and display the read image file.
3. Execute the program
4. Check the Workspace and get familiarized with newly Image variable
created with
Imread () function, Image matrix its content, size, availability of 3 colour
planes.
5. Modify the above written program and use following functions on the same
image and
observe the changes in workspace.
a. Imwrite b. size c. resize
d. ending each matlab statement with/without ‘;’ semicolon sign.
e. clc, clearall.
6. Observe the output and complete PART B of lab manual.
7. Save and close the file and name it as EXP1_Task1_your Roll no.m

TASK 3:

1. Create a new MATLAB file.


2. Read your input images.
3. Convert the color image into grayscale image.
4. Convert grayscale image into black-n-white image.
5. Complete PART B of lab manual.
6. Save and close the file and name it as EXP1_Task2_your Roll no.m
**********************

PART B
(PART B : TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments


within two hours of the practical. The soft copy must be uploaded
on the Blackboard or emailed to the concerned lab in charge
faculties at the end of the practical in case there is no Black board
access available)

Roll No. Name:


Class : Batch :
Date of Experiment: Date of Submission
Grade :

B.1 Software Code written by student:


(Paste your Matlab code completed during the 2 hours of practical in the lab
here)

B.2 Input and Output:


(Paste your program input and output in following format, If there is error
then paste the specific error in the output part. In case of error with due
permission of the faculty extension can be given to submit the error free code
with output in due course of time. Students will be graded accordingly.)

Input Images:

Output Images:

B.3 Observations and learning:


(Students are expected to comment on the output obtained with clear
observations and learning for each task/ sub part assigned)

B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual
outcome listed above and learning/observation noted in section B.3)

B.5 Question of Curiosity


(To be answered by student based on the practical performed and
learning/observations)

Q1: List out possible real-life applications of image Processing.

You might also like