Code covered by the BSD License  

Highlights from
Hough transform for circles

4.22222

4.2 | 10 ratings Rate this file 98 Downloads (last 30 days) File Size: 89.31 KB File ID: #26978
image thumbnail

Hough transform for circles

by David Young

 

16 Mar 2010 (Updated 19 Mar 2010)

A Hough transform function for detecting circles, optimised to allow search over radii.

| Watch this File

File Information
Description

The Hough transform may be used to detect circular shapes in images, after binarisation, for example by an edge detector. Often, functions to do this operation require the radius of the circle to be specified.

The function circle_hough allows a range of radii to be specified, so that the radius does not need to be known exactly in advance. It is likely to be faster than calling a standard function repeatedly for different radii.

Multiple circles may be detected by finding peaks in the 3D accumulator array which is output. A function, circle_houghpeaks, is provided for this. A demonstration of the two function is included as a script, circle_houghdemo.

The zip file includes an efficient and accurate implementation of circle approximation, without gaps, on an integer grid.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Hough Transform for circle detection

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
17 Apr 2010 Truc Phan

Great job! Thanks for sharing

06 May 2010 Alireza Saberi  
06 May 2010 Alireza Saberi

Hello David,
It should be nice fast work. Here I have following Qs:
1- by running demo file on my LAB system i can see the following error
??? Undefined command/function 'validateattributes'.

Error in ==> circle_hough at 41
validateattributes(rrange, {'double'}, {'real' 'positive' 'vector'});

Error in ==> circle_houghdemo at 26
h = circle_hough(e, radii, 'same', 'normalise');

2- I have an algorithm for fatigue detection of a driver/pilot
the final steps, I have binarized image around pupil and even if the eye is open, i want and i need a good hough transform detect partials of circle of pupil, Can it do that or circle should be perfect for detection?

06 May 2010 David Young

Alireza Saberi: As this page shows, the code was built using Matlab 2010a. You should not give a low rating just because you have an old version of Matlab. You can delete calls to validateattributes (though you will lose error checking) and it may then run on your system.

On your second point: this isn't the place to discuss a specific application, and I suggest post the question on the newsgroup.

07 May 2010 Alireza Saberi  
09 May 2010 Steve Stefanou  
23 Jul 2010 Masih Soltany

Hi

i want to use your code for my project on " eye detection "

i test but it had many miss place circle detection.

how can i optimize your code ?

thanks

24 Jul 2010 David Young

Mash: Sorry, but I can't help. There could be many different reasons why this technique does not work for your project, and you may need to investigate other methods, as well as experimenting to find good parameter values for the edge detection and the HT itself. You might get more detailed advice by posting a request (with example images) on the newsgroup.

29 Sep 2010 TaoGe ?

Hello,May Good Job.
But to me,an error found:??? Error: File: circle_houghpeaks.m Line: 113 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.

How to deal with it?
Thx~

30 Sep 2010 David Young

Hello TaoGe, I think you may be using an old version of Matlab that does not allow the use of ~ for anonymous variables. Please try replacing the ~ in line 113 of the file with a variable name, like this:

        [unused, ind] = sort(h(peakind), 'descend');

14 Dec 2010 Arefeh boroomand  
10 Aug 2011 Tristan

Awesome Code David, Thanks Alot.
The patch you just mentioned for older versions of matlab worked perfect for me in R2007b

22 Nov 2011 Nathan Orloff

I tried several of the different Hough Circle detection algorithms. None of them were as easy to use or as robust as this one. It was also very fast in comparison to the editors pick of the week. Even the script circlepoints turns out to be faster than a standard trick in drawing a circle in matlab. My only suggestion is that you be a little nicer to the newbs David... :)

22 Dec 2011 Ivan

wow, thanks a lot for the code David, helped with my project a lot!

just one question,

for example, if i were to set npeaks to 5, this will result in 5 circles being detected. however, i would only like one of the circle.

hence, is there a parameter i can set to eliminate the other circles? or do i have to add on to your code?

thank you so much!

24 Dec 2011 David Young

Hi Ivan, thanks for the comment. If you set npeaks to 1, you will get the circle with the strongest evidence. If that is not the right circle, then you will need additional code to select the circle you want, using some other selection criteria, such as radius or position.

09 Feb 2012 Fer  
Please login to add a comment or rating.
Updates
19 Mar 2010

Added circle_houghpeaks and circle_houghdemo, minor change to circle_hough to allow radius normalisation to be requested.

Tag Activity for this File
Tag Applied By Date/Time
hough transform David Young 17 Mar 2010 12:37:05
circle David Young 17 Mar 2010 12:37:05
image analysis David Young 17 Mar 2010 12:37:05
hough transform Stephen Gay 24 Jan 2011 15:43:32

Contact us at files@mathworks.com