4.78261

4.8 | 23 ratings Rate this file 265 downloads (last 30 days) File Size: 113.3 KB File ID: #9168

Detect circles with various radii in grayscale image via Hough Transform

by Tao Peng

 

27 Nov 2005 (Updated 08 Mar 2007)

Code covered by BSD License  

Detect circular shapes in a grayscale image. Resolve their center positions and radii.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | Watch this File

File Information
Description

Circular Hough transform based on the gradient field of an image.
1. Operates on grayscale images, NOT B/W bitmaps.
2. NO loops in the implementation of Circular Hough transform, which means faster operation but at the same time larger memory consumption.
3. Detection of radii works for concentric circles as well.

Acknowledgements
This submission has inspired the following:
Coin Segmentation
Required Products Image Processing Toolbox
MATLAB release MATLAB 7.0.4 (R14SP2)
Zip File Content  
Other Files CircularHough_Grd.m,
DrawCircle.m,
Frame_0_0022_portion.jpg,
license.txt,
TestImg_CHT_a2.bmp,
TestImg_CHT_a3.bmp,
TestImg_CHT_b3.bmp,
TestImg_CHT_c3.bmp
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (27)
20 Dec 2005 e d  
20 Dec 2005 Gijs H

Excellent work, well documented, easy to use.
Thanks!

30 Jan 2006 Iftach Nachman

Excellent! Works amazingly well in detecting yeast cells in microscopy images.

02 Mar 2006 ali volkan

Perfect

29 Apr 2006 Nurettin Senyer

Thank you for EXCELLENT work. Surely, well document and easy to use.

06 May 2006 veli birol

clearly and fast.

09 Jan 2007 Dany Simard

Clear and efficient

15 Jan 2007 Sander L

This code can be of great help in my project on pollen recognition in microscopic images. Thanks!

There is one problem however. For some(!) images I get the error message:
-----------------------------
??? Attempted to access SgnCv_LMPos(0); index must be a positive integer or logical.

Error in ==> CircularHough_Grd at 630
    cirrad(k) = SgnCv_LMPos(end);
-----------------------------
Can anyone help?

04 Mar 2007 Erinc D

Thanks for sharing this file, it helps a lot!
However, I'm having the same strange problem too (see below). I understand that this is an issue about radius range selection, but I cannot predict which values would make it work.

07 Mar 2007 Tao Peng

Hi, Sander and Erinc: The problem you have experienced is a bug in the code and it has been fixed (at least I think so :)). The revised version (March 7, 2007) will soon be posted by Matlab Central. Thank you for pointing out the problem.
Although I have requested that all user comments to be forwarded to my email, a couple of messages here seemed to have slipped. Therefore I would appreciate everyone who has questions about the code does send me emails. I can't guarantee a timely and satisfactory response but I'll do my best.

08 Mar 2007 Sander L

I've solved it by changing the code around line 650 into this:

% Save the detected radii
if (length(SgnCv_LMPos) ~= 0)
    cirrad(k) = SgnCv_LMPos(end);
    for i_radii = (length(SgnCv_LMPos) - 1) : -1 : 1,
        circen = [ circen; circen(k,:) ];
        cirrad = [ cirrad; SgnCv_LMPos(i_radii) ];
    end
end

30 Mar 2007 Paul Premakumar

Kudos to you!Your program is amazing. Your examples were great.
Thanks!

25 Apr 2007 hani ali

good article

03 Jun 2007 Dr Samir badawy

it straightforward. easy to follow and operate. not tested the programs on the MATLAB yet.

13 Jun 2007 Robert Keck

Note that this also requires the Signal Processing Toolbox since it uses the filtfilt function.

20 Sep 2007 Martin Ohmes

Excellent code with great documentation - this code saved my butt. It is a little memory intensive but with a few tweaks I got it working great for some detailed image analysis.

21 Sep 2007 Slobodan Vrhovac

This code can be of great help in my project on disk recognition in experiments with granular materials.

13 Nov 2007 Nat Angarita

Very good code, robust,...the only downside...it provides the values of the estimated radious as whole integers...could not see where I could change this in the code!

25 Apr 2008 Joan Wang

Excellent performance!

04 May 2008 Vinh Nguyen  
05 Jun 2008 Ohil K

I tried out this code, and I dont know if this problem can be solved. When I run the code on an image that has some straight lines too, all along the edge of the straight line, circles are detected. Is there a way to prevent this? I tried changing the threshold but to no avail.

08 Jan 2009 Lee Borland

Hi all. This may seem like a silly question, but how does one run an add on file such as this? I am attempting to detect circles in images. So far, the only code I have in matlab is open/close code to enhance my edges, then blob analysis to detect my circles and finally convex hull code to fill in my circles. So I now have a BW image containing 4 white circles, very much like the images in the examples.

Can someone advise as to how i now implement this file for radius calculations? I attempted to copy and paste but got the error: Error: Function definitions are not permitted at the prompt or in scripts.

Obviously missing something silly here, can anyone help??

15 Apr 2009 Roxy

I have been getting an error on one of your files when i try running it, there is no function name filtfilt.

08 Jul 2009 Gregory Van der Steen

Great work, excellent performance and good results. The algorithm is perfectly customizable by its number of parameters. Thanks, this was the important part of a solution for a problem of weeks.

11 Aug 2009 Ken Jarman

Excellent code and helpful comments on test cases. If you don't have IPToolbox or SPToolbox, you can still use this if you create or pick up a third-party version of bwlabel.m (labels blobs of dark/light pixels) and filtfilt.m (fwd/bkwd filter).

05 Oct 2009 Pavithra

thanks for sharing

12 Oct 2009 Samuele Lilliu  
Please login to add a comment or rating.
Updates
06 Dec 2005

Updated on Dec. 04, 2005.
A couple of minor changed were made. Algorithm remains untouched.

13 Feb 2006

Added the functionality of detecting the radii of circles.

08 Mar 2007

Fixed a bug in the code which causes the following problem:
??? Attempted to access SgnCv_LMPos(0); index must be a positive integer or logical.
Error in ==> CircularHough_Grd at 630
cirrad(k) = SgnCv_LMPos(end);

Tag Activity for this File
Tag Applied By Date/Time
image analysis Tao Peng 22 Oct 2008 08:07:53
circular hough transform Tao Peng 22 Oct 2008 08:07:53
various Tao Peng 22 Oct 2008 08:07:53
radius Tao Peng 22 Oct 2008 08:07:53
gradient Tao Peng 22 Oct 2008 08:07:53
potw Cristina McIntire 07 Nov 2008 13:21:31
image analysis sari abusabiha 31 Mar 2009 10:00:12
circular hough transform Bojan 09 Oct 2009 10:28:08
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com