Algorithms for Ellipsoid detection
*author : Konstantinos Lagogiannis 2017
I ve been looking for ellipse detection algorithms and I came across an interesting paper for which however I could not find code in C. So, here is my, yet unpolished implementation of the IEEE paper "A NEW EFFICIENT ELLIPSE DETECTION METHOD", Yonghong Xie & Qiang Ji 2002. \note Minor Customization have been added so as to improve detection ellipsoids in low-res images, but also show debug output of points used on an image - using OpenCV and Gcc.
Algorithm creates list of point pairs, and then checks/scores for candidate ellipse with major axis between a chosen pair of test points, it then estimates minor axis by testing all 3rd points and uses a voting procedure to check for possible minor axis and ellipse
*Example usage code :
cv::Canny( imgIn_thres, imgEdge_local, gi_CannyThresSmall,gi_CannyThres ); //Use an/any edge detection algorithm
getEdgePoints(imgEdge_local,vedgePoints_all); //Pass edge image, return list of points which we attempt to fit the ellipsoid.
detectEllipse(vedgePoints_all,qEllipsoids); //Run Ellipsoid fitting Algorithm returns detected ellipsoids
-
Store all edge pixels in a one dimensional array.
-
Clear the accumulator array .
-
For each pixel (x1, y1 ), carry out the following steps from (4) to (14).
-
For each other pixel (x2, y2), if the distance between (x1, y1) and (x 2, y2) is greater than the required least distance for a pair of pixels to be considered then carry out the following steps from (5) to (14).
-
From the pair of pixels (x1, y1) and (x2, y2), using equations (1) to (4) to calculate the center, orientation and length of major axis for the assumed ellipse.
-
For each third pixel (x, y), if the distance between (x, y) and (x0, y0) is ?greater? than the required least distance for a pair of pixels to be considered : *"The distance between (x, y) and (x_0 , y_0 ) should be less than the distance between (x_1 , y_1 ) and (x_0 ,y_0 ) or between (x_2 , y_2 ) and (x_0 , y_0 ) ." *found in MATlab implementation : ie 3rd point distance <= a; % (otherwise the formulae in paper do not work) then carry out the following steps from (7) to (9).
-
Using equations (5) and (6) to calculate the length of minor axis.
-
Increment the accumulator for this length of minor axis by 1.
-
Loop until all pixels are computed for this pair of pixels.
-
Find the maxium element in accumulator array. The related length is the possible length of minor axis for assumed ellipse. If the vote is greater than the required least number for assumed ellipse, one ellipse is detected.
-
Output ellipse parameters.
-
Remove the pixels on the detected ellipse from edge pixel array.
-
Clear accumulator array.
-
Loop until all pairs of pixels are computed.
-
Superimpose detected ellipses on the original image.
-
End.
- x 0 = (x 1 + x 2 )/2
- y 0 = (y 1 + y 2 )/2
- a = [(x 2 – x 1 ) + (y 2 – y 1 ) ] /2
- α = atan [(y 2 – y 1 )/(x 2 – x 1 )],
- b2 = (a 2 d 2 sin 2 τ)/( a 2 -d 2 cos 2 τ )
- cos τ = ( a 2 + d 2 – f 2 )/(2ad)
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.