Lab Manual

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

University of Engineering and Technology

Taxila
Sub campus Chakwal

Lab Manual

Course:
Machine Vision

Submitted to:
Engr. Naeem Zafar

Submitted By:

Department of Mechatronics Engineering

Lab No 1
Title:

Introduction to Machine Vision

Theory:

Machine vision (MV) is the technology and methods used to provide imaging-based
automatic inspection and analysis for such applications as automatic inspection, process
control, and robot guidance, usually in industry. Machine vision is a term encompassing a
large number of technologies, software and hardware products, integrated systems, actions,
methods and expertise. Machine vision as a systems engineering discipline can be considered
distinct from computer vision, a form of basic computer science. It attempts to integrate
existing technologies in new ways and apply them to solve real world problems. The term is
also used in a broader sense by trade shows and trade groups; this broader definition also
encompasses products and applications most often associated with image processing.

Digital image processing is the use of computer algorithms to perform image processing on
digital images. As a subcategory or field of digital signal processing, digital image processing
has many advantages over analogue image processing. It allows a much wider range of
algorithms to be applied to the input data and can avoid problems such as the build-up of
noise and signal distortion during processing. Since images are defined over two dimensions
(perhaps more) digital image processing may be modelled in the form of multidimensional
systems.

Lab No 2
Title:

To read the image in Matlab.

Theory:

In Matlab we can read any image using a specific syntax which contains file name and
format. Image reading through matlab is important because it gives the specifications of
image which will further help in processing of the image. Image reading in matlab can be
done by

Imread(‘filename.format’)

Task:

The task of this lab is to read the image from the matlab directory and find the specifications
of image such as size etc.

Output:

First Image:
Second Image:
Lab No 3

Title:

To read the image file in matlab from different locations.

Theory:

In the previous lab we have read the image from matlab directory. Now we will read image
from any location in the computer by giving address of image.

Task:

The task of this lab is to read the image from different locations in the computer beside
matlab directory and also find the size of image by using size command. Also we modify the
image by changing the range of bit values which changes the colour of image.

Output:

Location 1:
Location 2:
 Intensity of colours in above image can be changed by

This command means that below 90 colour is black and above 120 image is white.
The above image is then transformed into
Lab No 4

Title:

To convert image into different types

Theory:

In this lab we convert image into different types such as single, double and convert gray scale
image to black and etc. Image conversion is very important in machine vision because it will
be helpful in studying image better.

Task:

The task of this lab is to convert an image into 8 unit and to other types respectively. Also
here we will perform the commands of logical conversion.

Output:

s=im2unit16(a);

s=im2single(a);
Similarly we can convert the image into other types by following commands

 d=rgb2gray(a); // convert RGB image to gray image


 s=im2uint8(a); //convert image to uint8 image
 d=mat2gray(a); //convert image matrix to double type of values

Logical Command:

Logical Convert numeric values to logical. Logical(X) converts the elements of the array X
into logical, thus returning an array that can be used for logical indexing or logical tests.
Logical can have the values 0 and 1 corresponding to false and true, respectively. Any non-
zero real element of input array X is converted to a logical 1 while zeros in X become logical
0.
Lab No.05
Title:
Adjustment of the image
Theory:
In this lab will adjust the image by changing the different attributes of image. The image can
be adjusted by using (imadjust) command and also draw histogram by using (imhist)
command.
Programme code:
e=imread('cameraman.tif');
imshow(e)
Result:

h=imadjust(e,[0 1],[1 0])


Result:

With factor alpha


h=imadjust(e,[0 1],[1 0],10)% if gama <1 bright im, >1 will make it dark
imshow(h)
Result:

imhist(f)% histogram of a image


Lab No 06
Title:

 To draw histogram of images.


 To filter the image using filter command.

Theory:

In this lab we will draw the histograms of images and also filter the image. Histograms are of
different types such as stem histogram and bar histogram. Different commands can be used
for different histograms.

Image filtering is also a technique which is used to sharpen the image or to sharpen the
borders of image by adjusting the image.

Task:

The task of this lab is to draw different types of histograms of an image and also filter the
image.

Output:
Lab No 7

Title:

To count no of objects on image.

Theory:

Counting the number of objects is an integral part of image processing. Knowing the number
of objects present in the image can be useful for further analysis in a wide range of
applications. In this lab we propose a simple method for automatically determining the
number of objects in an image. Once the number of objects is determined the objects per unit
area or the density can also be estimated or we can say that we use this information for
further processing.

Task:

The task of this lab is to count the number of objects


on an image.

Output:

a=imread('rice.png')

imshow(a)

b=imopen(a,strel('disk',15))

surf(double(b(1:8:end, 1:8:end ))), zlim([0,255]);

set(gca,'ydir', 'reverse');
c=a-b

imshow(c)

d=imadjust(c)

e=im2bw(d)

imshow(e)

Lab No 09
Title:

 Applying filter on image with padding

Theory:

The padding property defines the innermost portion of the box model, creating space around
an element's content, inside of any defined margins and/or borders.

Padding values are set using lengths or percentages, and cannot accept negative values. The
initial, or default, value for all padding properties is 0.

Task:

The task of this lab is to filter the image and also applying padding on the image

Code:

close all
clear all
clc
a=imread('cameraman.tif'); %read the image
imshow(a)
a=im2double(a);
s=padarray(a,[1 1]); %command for padding of zeros
d=[1 1 1;1 -8 1;1 1 1];
g1=size(s);
output=zeros(g1);
[M N]=size(s);
%%loop for every entity of image for filtering
for c=(1:N-2)
i=c+1;
for l=(1:M-2)
o=l+1;
output(i,o)=sum(sum(s(i-1:i+1,o-1:o+1).*d));
end
end
imshow(output)
output;
t=im2uint8(output);
imshow(t)
imshow(output)

Output:
Lab No 11
Title:

 To prepare code for different attributes while not taking values from command
window.

Theory:

In matlab we can make functions of different attributes like area and circumference etc. and
then combine these in one main file. This will help in a way that the function is directly
called in the command window and hence it reduces the work.

Task:

The task of this lab is to create a main file in which area of rectangle, area of circle and
circumference of circle are combined in a single main file.

Code:

 Area of rectangle

function [a] = area(l,w)


%UNTITLED Summary of this function goes here
% Detailed explanation goes here

a=l*w;
end

 Area of circle

function [b] = area_c(r)


%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
b=pi*r*r;
end

 Circumference of circle:
function [c] = circum( r1)
%UNTITLED7 Summary of this function goes here
% Detailed explanation goes here
c=2*pi*r1
end
 Main file
function [d] = main( l,w,r,r1 )
net=area(l,w) + area_c(r);
d=net+circum(r1);
end

Output:
Lab No 12

Title:

 To perform high boost filtering or edge detection by low past filtering


 To study imfilter command
 To perform imnoise command

Theory :

Lab No 14

Title:

 To compare two images taken by webcam


 To study different commands of MATLAB

Theory:

We can compare two images in matlab by using different commands like win video. In this
method two different images are taken from the web cam and then these two images are
compared with each other. This application of matlab is used for security purpose in a way
that snapshots are taken at regular interval and if there is movement or disturbance in the
image then it can be spotted by comparing it with original image.

Task:

The task of this lab is to take to images from web cam of laptop and compare two images.
Secondly to study different built in commands of matlab
Code:

cam=videoinput('winvideo',1);
preview(cam)
getsnapshot(cam)
imshow(ans)
img = getsnapshot(cam)
imshow(img)
figure, imshow(img)
a=rgb2gray(ans)
imshow(a)
b=rgb2gray(img);
figure,imshow(b)
c=a-b
figure,imshow(c)
maxdiff=max(max(c));
[iRow,iCol]=max(c==maxdiff);
[m,n]=size(c);
figure,imshow(maxdiff)

Output:
Built in commands of Matlab:

 Logo

 Earth Map
 Eigshow

 Truss

 Lorenz
 Fifteen

 Image

You might also like