Calculate the center coordinate of circle

I'm a basic runner for openCV and image processing. Now using openCV to calculate the center point coordinate of the region of white pixels area like a link file. But that's not easy for me to find out exact center of this white circle. I think there are some steps to increase accuracy of center coordinate of it before finding the center point. Would you share your idea or any tip with me? Thanks and have a nice day

Image Path : http://blog.naver.com/colorring/220027355998 (Modified Path)

//---------------------------------------------------------------------------------------------------------------------------
// @@@ Source code
//---------------------------------------------------------------------------------------------------------------------------

IplImage* cimgGray = cvCreateImage( cvSize(m_OneimageXresolution, m_OneimageYresolution), IPL_DEPTH_8U, 1 );

cvCvtColor( m_Leftimg, cimgGray, CV_RGB2GRAY );

cvEqualizeHist(cimgGray,cimgGray); cvShowImage("cvEqualizeHist",cimgGray);

double threshold1 = cvThreshold(cimgGray, pImgOutput, 150, 255, CV_THRESH_BINARY); cvShowImage("cvThreshold",pImgOutput);

//----------------------------------------------------------------------------------------------------------------------------


To find the center of a circle or an ellipse in an image with high accuracy, you should use all the pixels at the edge of the circle. A nice way to do this is via the "Zhou Operator", which works like this:

  • Create an edge map for your image (Canny edge detector works well)

  • For each row (and column) of pixels in your edge map, scan for the brightest pixels (the pixels with the strongest edge response. You should find one brightness peak entering your circle, and one leaving (entry peak, exit peak). To estimate the edges of your circle with sub-pixel accuracy, fit a parabola to the pixels in the edge map around the two "peak" pixels. In the graph below, the highest red dot is the brightest edge pixel. Having fit the parabola, use calculus to find the x-value with zero slope - this gives you a sub-pixel location for the entry and exit points on your current row of pixels. 拟合抛物线以边缘映射像素来估计具有亚像素精度的最大响应的位置

  • Next, average your (sub-pixel) entry and exit points; this will give you a set of points which describe a line passing through the center of your circle (pictured below, with green pixels for the edges and red for points on the center-crossing lines).

  • 使用边缘像素(绿色)查找穿过中心的线条(红色)

  • You could use regression at this point to find best-fit lines for the mid-line points described in step three. However, using RANSAC to find a good-consensus line, then only including voters for the winning candidate in a least-mean-squares fit will boost your accuracy by about an order of magnitude (because scan-lines that just graze the circle have much higher error than other lines, and lead to outlier mid-points that will "poison" a straight Gaussian LMS fit, due to its assumption of a normal distribution of errors).
  • Depending on the size of your circle and the quality of your sensor, etc., you might obtain an error on the order of 1/50th to 1/100th of a pixel.


    There are multiple ways to tackle this issue. It would help if you shared some more details about the problem domain.

    One straightforward way to solve the problem would be to run a "distance transform" on a binarized version of the (already almost binary) image and then search for the maximal pixel value.

    FYI: I had to remove the ?type=w3 at the end of the link to see the image.


    Now that I can see your test image, I suggest a second possible approach - my other answer assumed a circle consisted of regions of "black" or "white" with a well-defined edge and no real gradient. This would mean that pixels away from the white/black boundary contained no information about the circle center, but this is not the case with your image.

    Depending on how accurately you want to locate the center of your image, you might consider an approach that uses information for more of the pixels, perhaps fitting, say, a degree-2 polynomial (or a spline, if a parabola isn't quite a good enough model) directly to rows and columns of pixels in your intensity map, and taking the maximum of the curve to be point on a line passing through the center of your circle (a red pixel in my answer). Because each parabola/spline would be built from many points, you should get very nice center points (noise in individual pixels will be largely cancelled by their neighbors).

    All this said, try the simplest approach first, and see if the accuracy and stability are good enough for your application.

    链接地址: http://www.djcxy.com/p/63814.html

    上一篇: 休眠JPA序列(非

    下一篇: 计算圆的中心坐标