Measure exact position of known circle using Python OpenCV - python

I have an image containing a bunch of circular features. I'd like to know exactly the exact location of the centre of a particular circle and its radius (preferably with sub-pixel accuracy).
Rather than using a circle detector, which will try to find all of the circles, is there a method in OpenCV for fitting a circle to the image? Like this:
Update:
I have tried using the Hough circle detection method, and it seems to get confused about whether the circle should be on the inside or outside edge of the black line. The circle jumps around between the inside and outside edges, or sometimes tries to do both.

All I can think of now is, if you know the approximate centre and radius, search for all the circles and use least fitting squares with the circle equation to find the one you are looking for.

Related

Python: How to replace curvilinear points within a circle with a line?

I have the following problem. If you take a look at the image below, you see a microscopic image of a circular strand of DNA, called a teardrop. An initial skeletonization (morphology.skeletonize) yielded the trace in red. The trace is an nd-array of shape (N, 2), where N is the number of points in my trace. In orange, the strand is traced after I applied some sort of improvement algorithm, which I designed myself. Now, as you can see, around the bright region, the trace twists a little bit and doesn't resemble the real shape. To work around that, I want to do the following:
Define a radius around the blue dot which is fixed (i.e. 5 nanometres)
Remove all points of the trace that lie within that radius (my problem)
After those points are removed, connect the blue dot with the first point that lies outside the circle
In the end, I don't know how I can tell Python that for a given array of coordinates, I want to delete all those that lie within an area of my image. That area is, as explained, a circle around the blue dot.

Python Fit circle with center outside of image

I have the following binary image of a disk, and extracted the border of it:
How can I calculate the center and the radius of the circle? I already tried some methods with cv2.HoughCircles() and cv2.findContours() + cv2.fitEllipse(), however these don't work with images where the circle center is far outside of the image.
You can find center of circle from 3 points, but for robust solution it is better to use ransac method. It uses a set of different solutions, for all your bounding points set and will give you more accurate solution. For instance check : here

Detecting center of image from parabolic mirror?

I have a panoramic one shot lens from here: http://www.0-360.com/ and I wrote a script using the python image library to "unwrap" the image into a panorama. I want to automate this process though, as currently I have to specify the center of the image. Also, getting the radius of the circle would be good too. The input image looks like this:
And the "unwrapped" image looks like this:
So far I have been trying the Hough Circle detection. The issues I have is selecting the correct values to use. Also, sometimes, dark objects near the center circle seem to throw it off.
Other Ideas I had:
Hough Line detection of the unwrapped image. Basically, choose center pixel as center, then unwrap and see if the lines on the top and bottom are straight or "curvy". If not straight, then keep trying with different centers.
Moments/blob detection. Maybe I can find the center blob and find the center of that. The problem is sometimes I get a bright ring in the center of the dark disk as seen in the image above. Also, the issue with dark objects near the center.
Paint the top bevel of the mirror a distinct color like green to make circle detection easier? If I use green and only use the green channel, would the detection be easier?
Whats the best method I should try and use to get the center of this image and possibly the radius of the outer and inner rings.
As your image have multiple circle with common centre you can move that way, like
Detect circle with Hough circle and consider circle with common centre.
Now check the ratio for co-centred circle, as your image keep that ratio constant.
I guess don't make it too fancy. The black center is at the center of the image, right? Cut a square ROI close to the image center and look for 'black' region there. Store all the 'black' pixel locations and find their center. You may consider using CMYK color space for detecting the black region.

Detect an arc from an image contour or edge

I am trying to detect arcs inside an image. The information that I have for certain with me is the radius of the arc. I can try and maybe get the centre of the circle whose arc I want to identify.
Is there any algorithm in Open CV which can tell us that the detected contour ( or edge from canny edge is an arc or an approximation of an arc)
Any help on how this would be possible in OpenCV with Python or even a general approach would be very helpful
Thanks
If you think that there will not be any change in the shape (i mean arc won't become line or something like this) then you can have a look a Generalized Hough Transform (GHT) which can detect any shape you want.
Cons:
There is no directly function in openCV library for GHT but you can get several source code at internet.
It is sometimes slow but can become fast if you set the parameters properly.
It won't be able to detect if the shape changes. for exmaple, i tried to detect squares using GHT and i got good results but when square were not perfect squares (i.e. rectangle or something like that), it didn't detect.
You can do it this way:
Convert the image to edges using canny filter.
Make the image binary using threshold function there is an option for regular threshold, otsu or adaptive.
Find contours with sufficient length (findContours function)
Iterate all the contours and try to fit ellipse (fitEllipse function)
Validate fitted ellipses by radius.
Check if detected ellipse is good fit - checking how much of the contour pixels are on the detected ellipse.
Select the best one.
You can try to increase the speed using RANSAC each time selecting 6 points from binarized image and trying to fit.
My math is rusty, but...
What about evaluating a contour by looping over its composite edge-nodes and finding those where the angle between the edges doesn't change too rapidly AND doesn't change sign?
A chain of angles (θ) where:
0 < θi < θmax
with number of edges (c) where:
c > dconst
would indicate an arc of:
radius ∝ 1/(θi + θi+1 + ...+ θn)/n)
or:
r ∝ 1/θave
and:
arclenth ∝ c
A way of finding these angles is discussed at Get angle from OpenCV Canny edge detector

circle detection using python, numpy?

I want to implement hough transform algorithm using python, numpy and scipy.
I do not want to use opencv.
I am trying to detect Center of circle or circle in image without known radius.
How do I proceed?
The process of implementing the Hough Transform is pretty straightfoward. I suggest you look on youtube for some videos about it, there are even videos with code/pseudocode for it.
That being said, I've been in the same situation, looking to implement the HT to detect circles. However, the approach I decided to use was a bit different than the traditional HT. Instead of looping over all pixels to generate the circles that passes on at leat one of the circle points, I used the circle points as centers, incrementing the radius from min_radius to max_radius and accummulating it in the same form as the classic HT.
This way, you will end up having a 3D array with (x, y and radius used). The center and radius will be the (x, y, radius) with the maximum accummulated value.
Simplified Hough Transform
I have googled a bit and I found the following:
http://nabinsharma.wordpress.com/2012/12/26/linear-hough-transform-using-python/
Maybe this is what you are searching.
Sorry I think for circles you should try the following:
http://nullege.com/codes/search/houghcircles

Categories

Resources