I have tried to use OpenCV HoughCircles and findContours to detect a circle however the circle isn't complete enough or there is too much noise in the algorithm for these algorithms. Or perhaps we are just not familiar enough with the OpenCV. Attached is my image that I need to find the circle on. You should be able to see it clearly with your eyes however, none of the circle detection algorithms seem to work. I have found that applying a median filter cleans up most of the noise but even after median filtering the algorithms can't detect the circle.
Note I even looked at and tried the solution here so it is not a duplicate of that question: Detect semi-circle in opencv
Any ideas? This is my source image that I need to use.
Also, the reason I want to detect the circle is I want to do a calculation using only the points that are a part of the circle.
Original Image: http://www.collegemobile.com/IMG_2021.JPG
Median Filtered Image: http://www.collegemobile.com/IMG_2022.JPG
Here you go:
I'm using my 2nd answer from Detect semi-circle in opencv and modify it a little. This version now detects the best found semi-circle (regarding completeness).
But first I want to tell you why the accepted answer of link to Detect semi-circle in opencv stack overflow question does not work here (beside noise): You have only edges of the circle! as stated in that question, HoughCircle function computes the gradient internally, which does not work well for edgy images.
But now how I do it:
using this as input (your own median filtered image (I've just cropped it):
First I "normalize" the image. I just stretch values, that smallest val is 0 and biggest val is 255, leading to this result: (maybe some real contrast enhancement is better)
after that I compute the threshold of that image with some fixed threshold (you might need to edit that and find a way to choose the threshold dynamically! a better contrast enhancement might help there)
from this image, I use some simple RANSAC circle detection(very similar to my answer in the linked semi-circle detection question), giving you this result as a best semi-sircle:
and here's the code:
with these helper functions:
edit : one more thing: speed performance highly depends on
maxNrOfIterations
. If that matters you really should read about RANSAC an when to stop it. So you might be able to decide early that a found circle is the right one and dont need to test any other ones ;)Mmmmm.... if you enhance the contrast on your image a little, you get this
which I think most algorithms are going to struggle with. As the actual circle is quite bright relative to the other (presumably) unwanted stuff, maybe consider thresholding at somewhere around the value 200.
I implemented a least square algorithm to fit a circle to 2d points. I applied the algorithm to the thresholded image from Micka but used a morphological opening to remove the outliers before.
Here is the result: