I have black and white image after binarization. After that I get one object with irregular shape. Link to this image is below. How can I inscribe this object to circle?? or How can I find "center" of this object??
-
Yoou want to find longest line drawable on the object and draw a circle with half its length as radius? – huseyin tugrul buyukisik Sep 12 '12 at 18:24
-
Link broken for me fyi -- never actually loads any png – Pyrce Sep 12 '12 at 18:25
-
@tuğrulbüyükışık I would think the "nieve" method is to merely average the positions of the "white" pixels? – Mooing Duck Sep 12 '12 at 18:39
-
@Pyrce: The link is slow, I got the actual image, and put it in the question. – Mooing Duck Sep 12 '12 at 18:40
-
Yes I want to find center of this object(white pixels) – user1666649 Sep 12 '12 at 18:57
-
1http://en.wikipedia.org/wiki/Center_of_mass – Software_Designer Sep 12 '12 at 19:12
-
1Depending on the method you use below, you may want to [close](http://homepages.inf.ed.ac.uk/rbf/HIPR2/close.htm) the image first. OpenCV can do that for you – Hammer Sep 12 '12 at 20:26
4 Answers
You can find the center of gravity of the pixels using a simple formula which is the sum of the x coordinates divided by the number of points and the sum of the y coordinates divided by the number of points (I mean white points).
Then you can draw a circle centered in the center of gravity with radious half of the maximum distance between points.
Here you have a graphic explanation for this.

- 22,059
- 20
- 123
- 164
This sounds like a smallest circle problem on the set of white pixels. It can be found in linear time in the number of pixels. This is the best you will ever get it your input is just an array of binary pixels.

- 7,809
- 1
- 38
- 49
well, you could scan from top down for the top-most white pixel, then from the bottom up for the bottom-most white pixel, same for left and right. that gives you a rectangle. finding the center of the rectangle is easy (e.g. left + ( right - left ) / 2), and that's your circle center. then find the distance to a corner (any will do), and that's your circle radius.

- 5,269
- 2
- 21
- 34
-
That doesn't product the minimal radius, I think. Consider the result of that algorithm against a filled white circle. – Robᵩ Sep 12 '12 at 19:28
I think, that center of the object can be easily found as an arithmetic mean of x and y coordinate. I you want to replace it by a circle, I'd say that the diameter is a double of the mean distance of all points to the center.

- 19
- 2