I need a very precise algorithm for fitting a circle to the set of data points (actually I need to determine the center). The data comes after the binarization and segmentation
"Best" depends on the kind of noise in the input data. The problem is trivial if there is no noise in the source data points: Just pick 3 points and calculate the circle.
If you expect normal distributed, independent translations of each data point, then a least mean squares algorithm should be optimal. The data points should fit the equation:
(x - xm)^2 + (y - ym)^2 = r^2
where xm
, ym
, r
are unknown, so:
x^2 - 2*x*xm + xm^2 + y^2 - 2*y*ym + ym^2 = r^2
substitute c
for r^2-xm^2-ym^2
and you have an overdetermined system of linear equations:
2*x*xm + 2*y*ym = c - x^2 - y^2
Any good linear algebra library (e.g. IPP) can solve that for you.
If you expect outliers in the data, I would suggest using a RANSAC-strategy to find the set of non-outlier points, then use the algorithm above to find the exact center for that set.