Having the idea of Hough line transform, it's easy to think about applying it to any shapes, such as circles, ellipses that can be expressed by a parameterized equation.
Given an ellipse (assume it's parallel to X-axis first), with center (a,b) and major/miner axis (m,n), we have four parameters to determine it. Of course we can use equation Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0 and do voting in multi-dimensional space, but it's too computationally expensive (O(n^5)), and boring, and noise-prone.
However, several researches have made the transform better by reducing the computation complexity of the process by (1) using programming techniques to simplify the implementation [1] [3] and (2) some characteristics of ellipses [2].
1. A useful characteristic of ellipses
I will introduce a theorem proved by Xiang [2].
Definition ---- Distance between a point p and an ellipse E, distance(p,E): the maximum of the distance between p and any points on E.
Theorem ---- For any given ellipse in a plane, which has point O as center, and any point p (different from O), distance(p,E)>distance(O,E).
Proof. Assume ellipse was x^2/a^2 + y^2/b^2 =1, a>b, distance(O,E)=a is a well-known fact.
Take a point P0 from the minor axis, connect P0 and g, the P0g>a, hence distance(P0,E)>a, that is, all points from minor axis has bigger distance() than distance(O,E).
Take point p1, draw a horizontal line meets major axis to p2, assume p3 is the point that make the distance between p1 and the ellipse largest, we will easily get p3p1>p3p2, therefore distance(p1,E)>distance(p2,E), so for p1 which is not on the ellipse, there exists a point p2 on ellipse,makes distance(p2,E) < distance(p1,E).
Also distance(p2,E)>a, hence distance(p1,E) > a.
From all above, distance(O,E) is the minimum of all {distance(p,E)} in plane.
The problem of this paper is it only detects single ellipse in the image.
2. Modified Hough transform to detect ellipses
Given an arbitrary ellipse, the equation can be written as:
3. The Algorithm
Now I can write the algorithm by cut the multi-dimensional Hough voting procedure to two 2-dimension voting. [1][2]
Algorithm:
Begin ---- Input image M
1. Do edge detection and thinning for M, get every single ellipse and create data structure {ei}, put the edge points in array A
2. For every point in image plane, calculate the distance from A, increment the accumulator.
3. Find local minimum points from the accumulator which are bigger than a threshold, they are the center of the ellipses, at the same time, a value in the accumulator is the length of major axis of an ellipse, accordingly.
4. After getting these 3 parameters <a,b,m>, then do Hough transform in 2-dimension space for (n,theta) by voting: for every possible theta (0 - 360 degrees), calculate n (minor axis length) accordingly, update the accumulator.
5. Find local minimum values bigger than a threshold in the accumulator and sort the results.
6. Display results.
7. End.
The experiment was to detect all ellipses in a binary image, the ellipses are all parallel to X-axis, which makes the program simpler to calculate.
Code is shared here, it can be compiled on Ubuntu with OpenCV 2.3 installed.
Reference:
[1] Saburo T, Fumio M. Detection of Ellipses by A Modified Hough Transformation.
[2] 周祥 等, 一种新的基于Hough变换的椭圆轮廓检测方法
[3] Yonghong X, Qiang J. A new efficient ellipse detection method.
Jian Nan
2012.3.27 in MN