You are on page 1of 4

Tennis Ball Detection Using Matlab Image Procesing

Aaqib Ali (2015002), Adnan Afzal (2015028)


Faculty of Electrical Engineering Faculty of Electrical Engineering
Ghulam Ishaq Khan Institute Ghulam Ishaq Khan Institute
U2015002@giki.edu.pk u2015028@giki.edu.pk
the object is detected based
Abstract— The project on the colour or shape and if
mainly focuses on the basis to the object is detected, then
implement the object detection the object’s colour is turned
and tracking based on its II. MAIN OBJECTIVES
to gray, using MATLAB code
roundness, which is a visual
based project i.e. the input to
image is converted to
 It should be capable threshold image to minimize
the project will be the image
data which is given by the user.
of detecting ball. the noise. Now if there is
It will detect the object from  It must be convert object present in the image, it
the given image. The visual image from RGB to will be detected on the basis
data captured then it is Binary of shape. Once the object is
processed using image  It must label the axis detected, the image
processing in MATLAB and and images. properties (i.e. Area,
the object is detected based on
 It should calculate perimeter and centroid) will
the color or shape and if the
object is detected, then the the parameters. be calculated.
object’s color is turned to gray,  It should give the
 Read a RGB image
using MATLAB code image is result on the basis of
with ball in midair
converted to threshold image shape and roundness
to minimize the noise. Now if or ball in palm.
of ball.
there is object present in the  The code must be  Convert the RGB
image, it will be detected on reliable. image to gray scale
the basis of shape. Once the
object is detected, the image  It should be able to image.
properties (i.e. Area, perimeter program image
 The pixel value
and centroid) will be processing.
greater than the
calculated.
III BLOCK DIAGRAM threshold value is
converted to one
else zero.
I. INTRODUCTION  Label the connected
Object detection can be done components using
by identifying and detecting ‘bwlabel’ function
some specific feature of the  Remove
object such as colour that components that are
belongs to the object smaller in size.
Detection using computer
vision is a crucial component  Find the image
in achieving robotic properties: Area,
surveillance. The main aim of Perimeter and
the object Detection is to Centroid
track the object based on the
information obtained from IV Working
images. In our project, we  Find the component
determine the region on Principle with the maximum
interest (ROI) of the target The project mainly focuses roundness value
which is followed adaptive on the basis to implement the  Show the detected
colour filter to extract the object detection and tracking table tennis ball
colour information and thus based on its roundness,
the object is tracked. The
main contribution on this which is a visual based
paper is that the introduction project i.e., the input to the
on a colour filtering method project will be the image data
which is given by the user. It
which is capable of
will detect the object from
V. Read the Image
adaptively identifying the
most salient colour feature the given image. The visual Read an image into the
that belongs to for object and data captured then it is workspace, using
using this colour and shape processed using image the imread command
feature for Detection processing in MATLAB and imread infers from the file
that the graphics file format registration techniques, and
is Tagged Image File Format batch-process large data sets.
(TIFF). Display the image, Visualization functions and
using the imshow function. apps let you explore images,
You can also view an image 3D volumes, and videos;
in the Image Viewer app. adjust contrast; create
The imtool function opens histograms; and manipulate
the Image Viewer app which regions of interest (ROIs). Fig. 4
presents an integrated Thresholding Image
environment for displaying
images and performing some
common image processing
VIII Ball Detection
tasks. The Image Viewer app After all the procedure,
provides all the image now the ball will be
display capabilities detected and the cross will
of imshow but also provides identify the ball detection.
access to several other tools There will be small cross
for navigating and exploring sign on the ball if detected.
images, such as scroll bars,
the Pixel Region tool, Image
Information tool, and the
Contrast Adjustment tool.
Fig 3 Image Processing Fig 6 Results
Fig. 2 Read
the image

Fig.5 ball
Detection

VI Image Processing
IX Equation
Image Processing Toolbox
provides a comprehensive set VII Threshold Image
of reference-standard Image thresholding is a
algorithms and workflow Using the formula:
simple, yet effective, way of
apps for image processing, partitioning an image into a
analysis, visualization, and foreground and background.
algorithm development. You Roundness =
This image analysis
can perform image technique is a type
segmentation, image of image segmentation that
enhancement, noise isolates objects by converting
reduction, geometric gray scale images into X Results
transformations, image binary images
registration, and 3D image
processing.
Image Processing Toolbox
apps let you automate
common image processing
workflows. You can
interactively segment image
data, compare image
% C=imcrop(Img,box);
binary label function
XI References %Find the centroid
%Remove components cen=Sdata(ele).Centroid
that is small and tiny ;
[1].
for i=1:total
https://www.mathwork
if(sum(sum(Label==i)) %Display the image
s.com/help/vision/grou
< 500 ) axes('Position',[0 .1 .74 .
nd-truth-labeling.html
Label(Label==i)=0; 8],'xtick',[],'ytick',[])
[2]. XII Appendix end imshow(Img);
https://www.mathwork Source Code: end hold on
s.com/products/image. Img = menu('Ball plot(cen(1,1),cen(1,2),'r
html Detection','Image') %Find the properties of x');%Mark the centroid
[3]. axes('Position',[0 .1 .74 . the image
https://www.mathwork 8],'xtick',[],'ytick',[]); Sdata = Rad=(Sdata(ele).EquivD
s.com/help/images/ima imshow(Img); regionprops(Label,'all'); iameter)/2;
ge-import-and- Rad=strcat('Radius of
export.html %Find the components the
number Ball :',num2str(Rad));
[4]. I=rgb2gray(Img); Un=unique(Label); radius=Rad;
https://angeljohnsy.blo % Converting RGB my_max=0.0;
gspot.com/2013/04/tabl Image to Area=Sdata(ele).Area;
e-tennis-ball-detection- % %Check the Roundness Area=strcat('Area of the
matlab-code.html Gray Scale Image metrics ball:',num2str(Area));
[5]. I=im2double(I); %Roundness=4*PI*Are A=Area;
https://www.mathwork % Converting Gray a/Perimeter.^2 Pmt=Sdata(ele).Perimet
s.com/products/image. scale Image for i=2:numel(Un) er;
html % to Roundness=(4*pi*Sdata Pmt=strcat('Perimeter of
Double type (Un(i)).Area)/Sdata(Un( the ball:',num2str(Pmt));
J = medfilt2(I,[3 3]); i)).Perimeter.^2; p=Pmt;
% Median Filter , my_max=max(my_max, Cen=Sdata(ele).Centroi
Roundness); d;
if(Roundness==my_max Cent=strcat('Centroid:',n
I2 = imadjust(J); ) um2str(Cen(1,1)),',',num
ele=Un(i); 2str(Cen(1,2)));
values end c=Cent;
end
title('Original Image');
choice = menu('Ball %Draw the box around
Detection','threshold') the ball
Ib = I2> 0.9627; box=Sdata(ele).Boundin
gBox;
box(1,1:2)=box(1,1:2)-
%Labelling 15;
[Label,total] = box(1,3:4)=box(1,3)+25
bwlabel(Ib,4); % ;
Indexing segments by
%Crop the image

You might also like