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

MCT-453: Machine Vision

Lab Session 9: Object detection and counting Using


Region Properties with Image Region Analyzer
Objective: This lab session would cover the MATLAB App Image Region
Analyzer. Further, will undergo the basics about binary thresholding, object region
properties (Area, centroid, diameter etc), counting detected objects and displaying
original image with circles and coin values placed on objects.

Problem Statement:
Machine vision systems can be used to automate objects detection and recognition.
Develop and implement MV-based application that can detect and count the
number of Saudi metal coins in an image. Your application should label each coin
piece by its weight and printout the total value of the coins in an image. Use the
given three images to test your developed application.
Img1, Img2, Img3

Output Image
Introduction to Image region Analyzer App in Matlab:

The Image Region Analyzer app measures a set of properties for each
connected component (also called an object or region) in a binary image and
displays this information in a table. You can also use this app to create other
binary images by filtering the image on region properties.
In this object detection method, it is necessary to have approximated Area
of each coin, Image Region Analyzer helps to interactively solve this issue. When
you click on any entry in the table on right, respective object would be
highlighted.

Steps: In command Window;

1. Reading an image (coins.png)


2. Converting grayscale image to binary image
3. Go to Matlab Apps, open the Image Region Analyzer App in
category Image processing and computer vision . In Image Region
Analyzer, Load Image from workspace, Find threshold range of area
for three types of coins.
Object Detection and Counting Algorithm:

function [coin1,SR1, SR5, SR10] = myfilterRegions(in_img)

This Algorithm involve following steps


∙ Reading a grayscale image (coins.png)
∙ Converting grayscale image to binary image
∙Remove small objects considered as noise if available
BW_in = bwareaopen(BW_in, 20);
∙ Filling holes in regions of binary image using imfill()
BW_in = imfill(BW_in,'holes');
∙ Finding region properties such as area and centre of objects using

prop = regionprops(BW_in, {'Area', 'Centroid','EquivDiameter'});


prop = struct2table(prop);

∙ Initialize three total count variables with zero value


SR1 = 0;
SR5 = 0;
SR10 = 0;

∙ Run a loop and use Area properties of coins to threshold different objects
i. count 1Halala, 5 Halala and 10 Halala coins and increment that coin
counter and place object annotation using centroid and radius value
coinImg = insertObjectAnnotation(coin1,'circle',[x y rad],...
'5 HALALS','LineWidth',3,'Color','red','FontSize',10);
SR5 = SR5+1;
ii. Place titles on image as shown in result.

∙ Show final image as animated image.


In Command Window,
Run above function with input argument coins.png
[coin1,SR1, SR5, SR10] = myfilterRegions(‘img1.png’)

To do: Paste your code below and result of three images.

You might also like