hough circle detection if circle extends outside of image?

asked 2017-10-09 05:08:39 -0600

Martian gravatar image

If an image contains a large circle, but the top or bottom extends slightly outside of the image (circle is clipped), is there still any way to use Hough to detect the circle? In my tests, even though 90% of the circle is inside the image, the Hough function seems to get thrown off by the slightly clipped top or bottom. The result is that the circle is slightly smaller than ideal, and skewed (usually toward the right).

If Hough will not handle this, is there another appropriate function?

edit retag flag offensive close merge delete

Comments

1

how about adding a border to your image before calling hough, like 10-20% extra? I know its a workaround, but might just do what you need.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-09 06:08:16 -0600 )edit

Thanks for that suggestion, Steven. It was a good idea. I did try extending the image, but for some reason. Hough draws a circle in an unexpected and illogical location, far from the very visible circle in the photo. It's-even worse than the first try, without the extended borders (???!).

The actual circle in the photo is crystal clear except for the truncated sections on top or bottom, so it's difficult to say how Hough is missing it. In the Hough function call, I did try restricting the size to a narrow range, but I don't think there is any way to restrict the location.

Martian gravatar imageMartian ( 2017-10-12 00:11:44 -0600 )edit

Slight amendment after more experiments: The border extension does help. Tweaking "inverse ratio of resolution", canny threshold, and center detect thresholds, and carefully restricting the acceptable range for circle diameter, I've been able to land closer. The diameter and center are still slightly off. Hough seems VERY sensitive to param changes. I haven't found any explanation for how to optimize those.

This thread suggests that OpenCV's implementation of HoughCircles is not as accurate as it could be: https://stackoverflow.com/questions/1... That's similar to what I'm seeing. The thread indicates that "Blob detection" can be more accurate (why?)

Martian gravatar imageMartian ( 2017-10-12 02:58:55 -0600 )edit

No idea on why it is not that accurate, but that said. a blob detection algorithm will never make edges where there are none ... about the border issues, can you maybe add some in between results in your question?

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-12 04:09:32 -0600 )edit

Hi Steven, Can you clarify what you mean by 'in between results'?

Basically, I'm looking at a gray-scale image that has a large, very obvious circle (from a circular lens). The contrast at the edges is extreme, so edge detection (Sobel, in this case?) should find that immediately. But unless I carefully hand-tweak Hough's parameters, it often misses by a mile, drawing a circle that's halfway across the image. I see nothing in the image that should lead it to such a conclusion: No arcs or other circular fragments.

This hasn't built confidence that it would succeed on other images. For example,applying a slight Gaussian blur on an image where HoughCircles had been working "OK", thoroughly confused it. I've restricted the diameter to a very narrow range too, so this should be very easy.

Martian gravatar imageMartian ( 2017-10-12 15:48:25 -0600 )edit

With in between results I mean, after each approach you try, give us an input and output sample. Visually it might help us understand what is wrong. Have you tried first doing edge calculation yourself and providing that edge image to the hough circle detector?

StevenPuttemans gravatar imageStevenPuttemans ( 2017-10-13 03:36:36 -0600 )edit

If all else fails, I'll try to figure out a way to upload source-processed image pairs. But I certainly can't make sense of this--very counterintuitive. Cleaner images giving more errors, etc. My recent experiment involved doing a histogram EQ to make contrast even more obvious, but of course, HoughCircles completely lost it on those images.

I did think of extracting the edges manually. Perhaps Sobel is going astray somehow. I was doing an adaptive threshold detection further downstream and getting very clean black and white image. I'll try doing the circle detect ops after that, and I'll let you know how it goes.

Thanks for the feedback, Steven!

Martian gravatar imageMartian ( 2017-10-13 14:29:48 -0600 )edit