0% found this document useful (0 votes)
287 views

Fundamentals of Image Processing Lab Manual SET 1

This document is a lab manual for the subject "Fundamentals of Image Processing". It provides instructions and examples for experiments involving reading, displaying, manipulating and processing digital images using MATLAB and SCILAB. The manual includes 15 listed experiments covering common image processing tasks like image arithmetic, filtering, morphological operations and more. Students are instructed to complete the experiments, write programs, and get faculty signatures in their lab manual after completing each task.

Uploaded by

Reza Arraffi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
287 views

Fundamentals of Image Processing Lab Manual SET 1

This document is a lab manual for the subject "Fundamentals of Image Processing". It provides instructions and examples for experiments involving reading, displaying, manipulating and processing digital images using MATLAB and SCILAB. The manual includes 15 listed experiments covering common image processing tasks like image arithmetic, filtering, morphological operations and more. Students are instructed to complete the experiments, write programs, and get faculty signatures in their lab manual after completing each task.

Uploaded by

Reza Arraffi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Fundamentals of

Image Processing
Laboratory Manual

Enrollment No. _______________


Name of the student:_________________________________

Government Engineering College, Rajkot

GOVERNMENT ENGINEERING COLLEGE, RAJKOT

CERTIFICATE

This

is

to

certify

that

Mr/Miss

____________________________________Enrollment No. _____________


of B.E. (E.C.) SEM-VIII has satisfactorily completed the term work
of the subject Fundamentals of Image Processing prescribed by
Gujarat Technological University during the academic term
January-2013 to April-2013.

Date:

Lab Manual of Fundamentals of Image Processing

Signature of the faculty

Page 2

List of Experiments
Sr.
No.
1.

Name of Experiment

11.

Write program to read and display digital image using MATLAB or


SCILAB
Write a program to perform convolution operation for 1D and 2D
data in MATLAB/SCILAB
To write and execute programs for image arithmetic operations
To write and execute programs for image logical operations
To write and execute program for geometric transformation of image
To understand various image noise models and to write programs for
image restoration
Write and execute programs to remove noise using spatial filters
Write and execute programs for image frequency domain filtering
Write a program in C and MATLAB/SCILAB for edge detection using
quick mask
Write a program in C and MATLAB/SCILAB for histogram calculation
and equalization. (Without using standard functions)
Write and execute programs of image manipulation Zoom and Shrink

12.

To process image using image processing toolbox

13.

Write and execute program to watermark given image

14.

Write and execute program for image morphological operations


erosion and dilation.

15.

To write and execute program for wavelet transform on given image


and perform inverse wavelet transform to reconstruct image.

2.
3.
4.
5.
6.
7.
8.
9.
10.

Instructions to the students:

Solve exercise given at the end of each practical, write answers and execute it

Write and execute all programs either in MATLAB or SCILAB. You can cut and
paste results of image processing in soft copy of this lab manual. Write all the
programs in separate folder. Prepare your folder in your laptop/computer.

Do not use standard MATLAB functions whenever specified. Write program


yourself without using standard functions

Get signature of staff regularly after completion of practical and exercise


regularly. Show your programs when faculty asks for it.

Prepare separate notebook to solve the assignments

Government Engineering College, Rajkot

Page 3

EXPERIMENT NO. 1
AIM: Write program to read and display digital image using MATLAB or
SCILAB
Introduction of SCILAB:
SciLab 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. It is similar to MATLAB. MATLAB is
commercial software while SCILAB is open source software. It has one
thousand four hundred in-built functions and it is growing day by day.
Image and Video processing toolbox will be useful for this subject.
Students can download free SCILAB software from following website:
http://www.scilab.in
You can also create your log in on the e-Prayog website:
http://59.181.142.81 and get scilab link from there. For image processing
experiments you need to download SIVP (Speech, Image, Video Processing)
Toolbox.
Saving and Loading Programs in SCILAB:
SCILAB can be used as a prototyping environment in which we try things
out, examine the results and then adjust our programs to give better
performance. We can give SCILAB commands on command prompt. For
large number of commands, we can use SCILAB editor. We can write
sequence of commands in SCILAB editor and then save as .sce files. We can
execute .sce file to see the execution of the program.
Some commands and programs in SCILAB:
[1] Declaring matrices:
In SciLab, 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 SCILAB command declares following matrix:
1 2 3
A = 4 5 6
7 8 9
Keep following things in mind while declaring variables/matrices:
No spaces
Dont start with a number
Variable names are case sensitive
Lab Manual of Fundamentals of Image Processing

Page 4

[2] Populating matrix elements with zeros:


SciLab 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)
0 0 0
B = 0 0 0
0 0 0

[2] Knowing size of matrix:


Syntax:
[rows, cols] = size(A);
This command 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 SciLab current directory. The current directory can be changed from the
main SciLab 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
SciLab using imshow function. This function simply takes the array storing
the image values as its only parameter.
Syntax:
imshow(<variable name>)
Example:
imshow(myImage);
Government Engineering College, Rajkot

Page 5

[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]Converting Color image into Grayscale image:
Color image can be converted into Grayscale image by matlab/scilab
command rgb2gray.
Example:
myGrayImage=rgb2gray(myImage)
[8] Flow control in SCILAB
If statements are simply used to make decisions in SciLab
Syntax:
if <condition> then
<do some work>
else
<do some other work>
end
If we wish to perform thresholding of an image we could use following
statements in SCILAB Program:
if ImageData(r, c) > threshold then
ThresholdedImage(r, c) = 255;
else
ThresholdedImage(r, c) = 0;
end

Lab Manual of Fundamentals of Image Processing

Page 6

[8] Loops in SCILAB:


There is for loop and while loop in SCILAB.
While loop
While loop repeat a piece of work as long as a condition holds true.
The while loop in SciLab uses the following syntax:
while <condition>
<perform some work repeatedly>
end
For loop in SCILAB is very popular for image processing because it is
particularly useful for iterating through the members of a matrix.
The SCILAB for loop uses the following syntax:
for index = <start>:<finish>
<Perform some work>
end
Example:
Following SCILAB code iterates through each pixel of image, does
summation of pixel values, finds average pixel value which represents
average brightness of the scene.
myImage=imread(/home/chv/test.bmp)
[Rows, Cols] = size(myImage)
total = 0;
for rowIndex = 1:Rows
for colIndex = 1:Cols
total = total + ImageData(rowIndex, colIndex);
end
end
average=total/(Rows*Cols)
[9] Saving two dimensional matrix in Image file
We read image, image data is available in two dimensional matrix. We
process the matrix. After processing, we need to save the processed data in
form of image. To save image data in image file, following command is used.
imwrite(ImageData, ' Testout.bmp', 'bmp');
This command writes ImageData in file Testout.bmp. It also supports gif,
jpg and png file formats.
[10] Program to flip the given image horizontally:
//Read in an image
Moon = imread("Moon.bmp")
Moon=rgb2gray(Moon)
//Display the image
imshow(Moon);
Government Engineering College, Rajkot

Page 7

//Determine the size of the image


[rows,cols] = size(Moon);
//Declare a new matrix to store the newly created flipped image
FlippedMoon = zeros(rows,cols);
//Generate the flipped image
for r = 1:rows
for c = 1:cols
FlippedMoon(r,cols+1-c) = Moon(r,c);
end;
end;
//Display the flipped image
imshow(FlippedMoon,[]);
//Write an image to a file
imwrite(mat2gray(FlippedMoon),'HoriFlippedMoon99.bmp');

:: WORKSHEET ::
[1] Give following commands in SCILAB, observe output and write
explanation of each command
t = 0:0.01:1
y=sin(2*%pi*10)
plot(y)

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

Lab Manual of Fundamentals of Image Processing

Page 8

[2] Create image of size 512x512 black square using monochrome, 256
gray-level using paint or any other relevant software. Read and display
image using SCILAB commands

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[3] Execute following program for the image created in exercise[2] and
observe the result. Write comments on the result :
imgData=imread('white.bmp');
[Rows,Cols]=size(imgData);
imshow(imgData);
for i=1:Rows
for j=1:Cols
if(i>Rows/4 && i<3*Rows/4)
if(j>Cols/4 && j<3*Cols/4)
imgData(i,j)=0;
end
end
end
end
figure;
imshow(imgData);
Government Engineering College, Rajkot

Page 9

Write your comments on the result after executing the program:

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[3] Write program to read image, create negative image, display original and
negative image : (Hint: for negative image subtract pixel value from 255)

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Lab Manual of Fundamentals of Image Processing

Page 10

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Copy and paste original image and negative image here:

Government Engineering College, Rajkot

Page 11

EXPERIMENT NO. 2
AIM: Write a program to perform convolution operation for 1D and 2D data
in MATLAB/SCILAB
Program for 1D convolution:
clear;
clc;
x=input("Enter value of x: ")
y=input("Enter value of y: ")
n=length(x)
k=length(y)
for z=n+1:n+k-1
x(z)=0;
end
for u=k+1:n+k-1
y(u)=0;
end
for i=1:n+k-1
s(i)=0
for j=1:i
s(i)=(x(j)*y(i-j+1))+s(i)
end
end
subplot(3,1,1)
plot2d3(x)
subplot(3,1,2)
plot2d3(y)
subplot(3,1,3)
plot2d3(s)
Take value of x: [ 1 2 3 4 5 6 7 8 9 0 10 11 12 13 14 15]
Y: [-1 1]
Observe result of convolution and write your comments:

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Lab Manual of Fundamentals of Image Processing

Page 12

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Program for 2D convolution:
clear;
clc;
x=input("Enter value of x in matrix form: ")
y=input("Enter value of y in matrix form: ")
[xrows,xcols]=size(x);
[yrows,ycols]=size(y);
result=zeros(xrows+yrows,xcols+ycols)
for r = 1:xrows-1
for c = 1:xcols-1
sum=0;
for a=0:yrows
for b=0:ycols
sum=sum+x(r+a,c+b)*y(a+1,b+1);
end
end
result(r,c)=sum;
end
end
Enter following 2D matrix for x:
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10

Enter following 2D matrix for y:


Government Engineering College, Rajkot

Page 13

1 1 1
0
1

0
1

0
1

Observe output values and write your comments

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Write program of 2D convolution for image i.e. get variable x by reading
image pixels, use any 3x3 mask as variable y, process the result and write
your comments

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Lab Manual of Fundamentals of Image Processing

Page 14

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

Copy and paste original image processed image (Separate page)

Government Engineering College, Rajkot

Page 15

EXPERIMENT NO. 3
AIM: To write and execute programs for image arithmetic operations
Introduction:
Arithmetic operations like image addition, subtraction,
multiplication and division is possible. If there is two images I1 and I2 then
addition of image can be given by:
I(x,y) = I1(x,y) + I2(x,y)
Where I(x,y) is resultant image due to addition of two images. x and y are
coordinates of image. Image addition is pixel to pixel. Value of pixel should
not cross maximum allowed value that is 255 for 8 bit grey scale image.
When it exceeds value 255, it should be clipped to 255.
To increase overall brightness of the image, we can add some constant value
depending on brightness required. In example program we will add value 50
to the image and compare brightness of original and modified image.
To decrease brightness of image, we can subtract constant value. In example
program, value 100 is subtracted for every pixel. Care should be taken that
pixel value should not less than 0 (minus value). Subtract operation can be
used to obtain complement (negative) image in which every pixel is
subtracted from maximum value i.e. 255 for 8 bit greyscale image.
Multiplication operation can be used to mask the image for obtaining region
of interest. Black and white mask (binary image) containing 1s and 0s is
multiplied with image to get resultant image. To obtain binary image
function im2bw() can be used. Multiplication operation can also be used to
increase brightness of the image
Division operation results into floating point numbers. So data type required
is floating point numbers. It can be converted into integer data type while
storing the image. Division can be used to decrease the brightness of the
image. It can also used to detect change in image.
Execute following MATLAB program:
%Experiment No. 3 Image Arithmetic Operations
%Image Processing Lab, E.C. Department, GEC Rajkot
%Image addition is done between two similar size of image, so image resize
%function is used to make size of both image same.
%I=I1+I2
clc
close all
I1 = imread('cameraman.tif');
I2 = imread('rice.png');
Lab Manual of Fundamentals of Image Processing

Page 16

subplot(2, 2, 1);imshow(I1);title('Original image I1');


subplot(2, 2, 2);imshow(I2);title('Original image I2');
I=I1+I2; % Addition of two images
subplot(2, 2, 3);imshow(I);title('Addition of image I1+I2');
I=I1-I2; %Subtraction of two images
subplot(2, 2, 4);imshow(I);title('Subtraction of image I1-I2');
figure;
subplot(2, 2, 1);imshow(I1);title('Original image I1');
I=I1+50;
subplot(2, 2, 2);imshow(I);title('Bright Image I');
I=I1-100;
subplot(2, 2, 3);imshow(I);title('Dark Image I');
M=imread('Mask.tif');
M=im2bw(M) % Converts into binary image having 0s and 1s
I=uint8(I1).*uint8(M); %Type casting before multiplication
subplot(2, 2, 4);imshow(I);title('Masked Image I');
Result after execution of program:
Original image I1

Original image I2

Addition of image I1+I2

Subtraction of image I1-I2

Government Engineering College, Rajkot

Page 17

Original image I1

Bright Image I

Dark Image I

Masked Image I

Exercise:
[1] In above program, use functions imadd() functions to addition,
imsubtract() for subtraction immultiply() for multiplication operations.
Use imcomplement() function to get complement of image. Write
program again using these functions in following space.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Lab Manual of Fundamentals of Image Processing

Page 18

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[2] Write Program to read any image, resize it to 256x256. Apply square
mask shown in following figure so that only middle part of the image is
visible.

128

256

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

Government Engineering College, Rajkot

Page 19

EXPERIMENT NO. 4
AIM: To write and execute programs for image logical operations
Introduction: Bitwise logical operations can be performed between pixels of
one or more than one image.
AND/NAND Logical operations can be used for following applications:
Compute intersection of the images
Design of filter masks
Slicing of gray scale images
OR/NOR logical operations can be used for following applications:
Merging of two images
XOR/XNOR operations can be used for following applications:
To detect change in gray level in the image
Check similarity of two images
NOT operation is used for:
To obtain negative image
Making some features clear
Program:
Experiment No. 4 Image Logical Operations
%Image Processing Lab, E.C. Department, GEC Rajkot
%Logical operations between two image circle and pentagon is shown
clc
close all
clc
close all
myimageA=imread('circle.jpg');
myimageA=rgb2gray(myimageA);
myimageB=imread('pentagon.jpg');
myimageB=rgb2gray(myimageB);
subplot(3,2,1)
imshow(myimageA),title('Image A ');
% Display the Original Image B
subplot(3,2,2)
imshow(myimageB),title('Image B');
% Take a complement of Image A and Display it
subplot(3,2,3)
cimageA= ~myimageA ;
imshow(cimageA), title('Complement of Image A');
% Take a Ex-OR of Image A and Image B and Display it
subplot(3,2,4)
xorimage= xor(myimageA,myimageB);
imshow(xorimage), title('Image A XOR Image B');
Lab Manual of Fundamentals of Image Processing

Page 20

% Take OR of Image A and Image B and Display it


subplot(3,2,5)
orimage= myimageA | myimageB;
imshow(orimage), title('Image A OR Image B ');
% Take AND of Image A and Image B and Display it
subplot(3,2,6)
andimage= myimageA & myimageB;
imshow(andimage), title('Image A AND Image B ');

Result after execution of program:


Image A

Image B

Complement of Image A

Image A XOR Image B

Image A OR Image B

Image A AND Image B

Exercise:
[1] Prepare any two images of size 256x256 in paint. Save it in JPEG format
256 gray levels. Perform logical NOR, NAND operations between two images.
Write program and paste your results.

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Government Engineering College, Rajkot

Page 21

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Result after execution of program:
(Copy and paste original and processed image here)

Lab Manual of Fundamentals of Image Processing

Page 22

EXPERIMENT NO. 5
AIM: To write and execute program for geometric transformation of image
Introduction: We will perform following geometric transformations on the
image in this experiment
Translation: Translation is movement of image to new position.
Mathematically translation is represented as:
x = x +x and y = y + y
In matrix form translation is represented by:

x '

1
y' 1 = 0
0

x
y
1

0
1
0

x
y

1

Scaling: Scaling means enlarging or shrinking. Mathematically scaling can


be represented by:
x = x Sx and y = y Sy
In matrix form scaling is represented by:

x '

S x
y' 1 = 0
0

0
Sy
0

0
0
1

x
y

1

Rotation: Image can be rotated by an angle , in matrix form it can be


represented as:
x = xcos - ysin and y = xsin + ycos
In matrix form rotation is represented by:

x '

cos
y' 1 = sin
0

sin
cos
0

0
0
1

x
y

1

If is substituted with -, this matrix rotates the image in clockwise


direction.
Shearing: Image can be distorted (sheared) either in x direction or y
direction. Shearing can be represented as:

x = shx y

y = y

In matrix form rotation is represented by:

Government Engineering College, Rajkot

Page 23

1
Xshear= sh x
0

0
1
0

0
0
1

x
y

1

Shearing in Y direction can be given by:

x = x

y = y shy

1
Yshear= 0
0

sh y
1
0

0
0
1

x
y

1

Zooming : zooming of image can be done by process called pixel replication


or interpolation. Linear interpolation or some non-linear interpolation like
cubic interpolation can be performed for better result.
Program:
%Experiment No. 4 Image Geometric transformations
%Image Processing Lab, E.C. Department, GEC Rajkot
%To rotate given image using standard Matlab function imrotate()
%To transform image using standard Matlab function imtransform()
% using shearing matrix.
clc
close all
filename=input('Enter File Name :','s');
x=imread(filename);
x=rgb2gray(x);
subplot(2,2,1); imshow(x); title('Orignial Image');
y=imrotate(x,45,'bilinear','crop');
subplot(2,2,2); imshow(y); title('Image rotated by 45 degree');
y=imrotate(x,90,'bilinear','crop');
subplot(2,2,3); imshow(y); title('Image rotated by 90 degree');
y=imrotate(x,-45,'bilinear','crop');
subplot(2,2,4); imshow(y); title('Image rotated by -45 degree');
x = imread('cameraman.tif');
tform = maketform('affine',[1 0 0; .5 1 0; 0 0 1]);
y = imtransform(x,tform);
figure;
subplot(2,2,1); imshow(x); title('Orignial Image');
subplot(2,2,2); imshow(y); title('Shear in X direction');
tform = maketform('affine',[1 0.5 0; 0 1 0; 0 0 1]);
y = imtransform(x,tform);
subplot(2,2,3); imshow(y); title('Shear in Y direction');
tform = maketform('affine',[1 0.5 0; 0.5 1 0; 0 0 1]);
Lab Manual of Fundamentals of Image Processing

Page 24

y = imtransform(x,tform);
subplot(2,2,4); imshow(y); title('Shear in X-Y direction');
Result after execution of program:
Orignial Image

Image rotated by 45 degree

Image rotated by 90 degree

Image rotated by -45 degree

Result after execution of program:

Orignial Image

Shear in Y direction

Government Engineering College, Rajkot

Shear in X direction

Shear in X-Y direction

Page 25

Exercise:
[1] In above program, modify matrix for geometric transformation and use
imtransform() function for modified matrix. Show the results and your
conclusions.
Program:

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Result after execution of program:

Conclusion:

Lab Manual of Fundamentals of Image Processing

Page 26

Note for the students:


Experiments given in this laboratory manual is only for guidance. Students
may modify SCILAB/MATLAB code and do some innovative changes. They
can write experiments as per their creativity and imagination. Experiments
given are minimum requirement. You can add more experiments also.
Laboratory Manual of each student should be unique.
You have to show soft copy whenever faculty asks for it. Please upload your
Matlab program and lab manual copy to your Email Id or alternatively you
can store it in CD/Pen drive to protect your work
There are total 3 SETs. Each set has five experiments. After completion
of each set, you have to take print out and get signature of the faculty
immediately.

Government Engineering College, Rajkot

Page 27

You might also like