# Detecting and Counting Objects with Circular Features

This example shows how you can use* imfindcircles* together with *removeoverlap *function (can be found in the file exchange), for counting fungi spores, which has various elliptical like shapes.

imshow(image);

As you can see, the spores have different shapes and sizes, some overlap objects from other planes of the imaged sample. This is a common microscopy problem in biology.

First, try to find circles in the image using *imfindcircles. For estimating the radius range of our objects we can use imdisline:*

l= imdistline;

Using a radius range between 12 to 30 pixel and visualizing the results with *viscircles:*

[centers, radii] = imfindcircles(image,[12 30]); close all;figure; imshow(image); viscircles(centers, radii,'EdgeColor','b');

Lets increase the Sensitivity factor (the default is 0.85) and use a low static Edge Gradient Threshold instead of the default graytreshold.

[centers, radii] = imfindcircles(image,[12 30],'Sensitivity',0.92,'Edge',0.03); close all;figure; imshow(image); viscircles(centers, radii,'EdgeColor','b');

Now, it seems we detected more circles than spores, mostly because of overlapping circles. Using *removeoverlap *function we can remove the overlapping circles, or allow an overlap of circle pair up to some tolerance, e.g: 5 pixels overlap.

[centersNew,radiiNew]=RemoveOverLap(centers,radii,5,1); close all;figure; imshow(image); viscircles(centersNew, radiiNew,'EdgeColor','b');

We got a relatively good detection for the number of spores, finally we can count the number of circles.

length(centersNew) ans = 94

So, we counted 94 spores!

very good tutorial about matlab and the way for detection objects. An article with tutorials about how Matlab can be used for object detection and tracking is http://www.intorobotics.com/how-to-detect-and-track-objects-using-matlab/

I did’nt saw imfindcircles and removeoverlap funtions in MATLAB. How can I use it if I don’t see it ?

for imfindcircles you need MATLAB version of R2012a or later and the image processing toolbox installed.

removeoverlap function is available in the MATLAB file exchange: http://www.mathworks.com/matlabcentral/fileexchange/42370-circles-overlap-remover

Does the ans= 94 is count manually or automatic by matlab??

It’s all automatic

Excuse me, I wonder Where can I find IPT (image processing toolbox)? I got one but I’m not sure It says ver 2,1 and his size is 69,1 mb.Is that one? Can you help me, please? I need it for my project By the way….nice blog

Try these links below

http://www.mathworks.com/products/image/code-examples.html

http://www.mathworks.com/products/computer-vision/code-examples.html

http://www.mathworks.com/products/imaq/code-examples.html

http://www.mathworks.com/products/mapping/code-examples.html