Code covered by the BSD License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

### Highlights from Ellipse Detection Using 1D Hough Transform

4.33333
4.3 | 11 ratings Rate this file 69 Downloads (last 30 days) File Size: 25.2 KB File ID: #33970 Version: 1.2

# Ellipse Detection Using 1D Hough Transform

### Martin Simonovsky (view profile)

28 Nov 2011 (Updated )

An efficient ellipse detector based on Hough voting

File Information
Description

Overview:
--------
Fits an ellipse by examining all possible major axes (all pairs of points) and getting the minor axis using Hough transform. The algorithm complexity depends on the number of valid non-zero points, therefore it is beneficial to provide as many restrictions in the "params" input arguments as possible if there is any prior
knowledge about the problem.

The code is reasonably fast due to (optional) randomization and full code vectorization. However, as the algorithm needs to compute pairwise point distances, it can be quite memory intensive. If you get out of memory errors, either downsample the input image or somehow decrease the number of non-zero points in it. It can deal with big amount of noise but can have severe problem with occlusions (major axis end points need to be visible)

Input arguments:
--------
img
- One-channel input image (greyscale or binary).
params
- Parameters of the algorithm:
* minMajorAxis: Minimal length of major axis accepted.
* maxMajorAxis: Maximal length of major axis accepted.
rotation, rotationSpan: Specification of restriction on the angle of the major axis in degrees. If rotationSpan is in (0,90), only angles within [rotation-rotationSpan, rotation+rotationSpan] are accepted.
* minAspectRatio: Minimal aspect ratio of an ellipse (in (0,1))
* randomize: Subsampling of all possible point pairs. Instead of examining all N*N pairs, runs only on N*randomize pairs. If 0, randomization is turned off.
* numBest: Top numBest to return
* uniformWeights: Used to prefer some points over others. If false, accumulator points are weighted by their grey intensity in the image. If true, the input image is regarded as binary.
* smoothStddev: In order to provide more stability of the solution, the accumulator is convolved with a gaussian kernel. This parameter specifies its standard deviation in pixels.

Return value:
--------
Returns a matrix of best fits. Each row (there are params.numBest of them) contains six elements: [x0 y0 a b alpha score] being the center of the ellipse, its major and minor axis, its angle in degrees and score.

Based on:
--------
- "A New Efficient Ellipse Detection Method" (Yonghong Xie Qiang , Qiang Ji / 2002)
- random subsampling inspired by "Randomized Hough Transform for Ellipse Detection with Result Clustering" (CA Basca, M Talos, R Brad / 2005)

Update log:
--------
1.1: More memory efficient code, better documentation, more parameters, more solutions possible, example code.
1.0: Initial version

Required Products Image Processing Toolbox
MATLAB
MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Comments and Ratings (25)
18 Jul 2016 Agustin Trujillo-Pino

### Agustin Trujillo-Pino (view profile)

Good detection in most of cases!

But I have a question: the minor axis seems to be always an integer value. Is it possible to obtain more accuracy in this parameter?

11 Jan 2016 shanhu yijiao

### shanhu yijiao (view profile)

??? Subscript indices must either be real positive integers or logicals

Error in ==> example at 18
image(I);

Can you help me please to fix this...

Comment only
11 Jan 2016 shanhu yijiao

### shanhu yijiao (view profile)

11 Jan 2016 shanhu yijiao

### shanhu yijiao (view profile)

i have download the code from http://www.mathworks.com/matlabcentral/fileexchange/289 for drawing an ellipse.
it runs out of memory due to index size!
Error using bsxfun
Out of memory. Type HELP MEMORY for your options.

Any fix???

05 Nov 2015 Hongming

### Hongming (view profile)

great code

03 Aug 2015 Javeria Farooq

### Javeria Farooq (view profile)

hii,I am working on head detection using hough transform, I am trying to implement this algorithm for head detection but I am unable to achieve the required result....can u please help me regarding this...

Comment only
06 May 2015 Muhammad Zubair Afzal

### Muhammad Zubair Afzal (view profile)

it runs out of memory due to index size!

Error using bsxfun
Out of memory. Type HELP MEMORY for your options.

Any fix???

Comment only
27 Nov 2014 Nitay Megides

### Nitay Megides (view profile)

Good work! I'm getting an "Out of memory" error when I try to use uniformWeights as false

10 Jul 2014 Christian

### Christian (view profile)

16 Jun 2014 Antonio Scrima

### Antonio Scrima (view profile)

Good Job!!!

14 May 2014 Omar Al Okashi

### Omar Al Okashi (view profile)

Dear Sir, Thank you very much for your valuable work... when I run your example I got this error message:

??? Subscript indices must either be real positive integers or logicals

Error in ==> example at 18
image(I);

Can you help me please to fix this...

Comment only
14 May 2014 Nicole Kovacs

### Nicole Kovacs (view profile)

Really liked it! Congratulations!

02 Apr 2014 Hemo khalifa

### Hemo khalifa (view profile)

it's not working

Comment only
12 Sep 2013 Georgi

### Georgi (view profile)

Can you please tell me what to change to detect more than one ellipse in one image(for example 3 ellipses)
It's very important!
Thank you in advance

Comment only
09 Sep 2013 Georgi

### Georgi (view profile)

I am talking about the hough matrix.
Is it possible to dispay it and if it is possible which is the code?

Comment only
05 Sep 2013 Georgi

### Georgi (view profile)

Hello again,
i handle with the 1 fit.
But is it possible to get the graphic of the Hough transform and if it is,what is the code?

Comment only
05 Sep 2013 Georgi

### Georgi (view profile)

*graphic

Comment only
04 Sep 2013 Georgi

### Georgi (view profile)

Hello,
first.congratulation for the excellent work!
I have a question,how to change the code to have 1 fit at the picture at the end,only one draw of the ellipse, not 3(the best fit)

Comment only
19 Apr 2013 leon

### leon (view profile)

Hi Martin Simonovsky,

can you teach me how to use the coding to ellipse detect the image below. I really need your help, i had try many method but cannot ellipse detect the object.now i had out of time. really need your help,your help waill be appreciated.
Thank you.

http://snag.gy/oSz2X.jpg http://snag.gy/UBlgG.jpg http://snag.gy/e8mJG.jpg http://snag.gy/sI69L.jpg http://snag.gy/Rz8dB.jpg

Comment only
05 Dec 2012 Andri Pranata

### Andri Pranata (view profile)

heres my email if you please :) andripranatakusuma@hotmail.com

Comment only
05 Dec 2012 Andri Pranata

### Andri Pranata (view profile)

hey martin, im andri from indonesia. your code maybe is a modified form of old ellipse detection method, maybe :p before you create this code, is there any old ellipse detector you have? could you send me that code to my email? thank you martin :)

Comment only
25 Apr 2012 Brill

### Brill (view profile)

High speed, but not very satisfactory result.

10 Mar 2012 Martin Simonovsky

### Martin Simonovsky (view profile)

Hao zheng Yan: See e.g. http://www.mathworks.com/matlabcentral/fileexchange/289 for drawing an ellipse.

Comment only
04 Jan 2012 Hao zheng Yan

### Hao zheng Yan (view profile)

04 Jan 2012 Hao zheng Yan

### Hao zheng Yan (view profile)

The code is very Conciseļ¼But the function of drawing ellipse is not submited.Can you submit a testing image?