1

I have to detect circles in images (some of them don't have homogeneous background), for that I'm using the circle_hough function, which needs the edges logical matrix.

i_edge = edge(image, 'Canny', 0.3); %0.3 works in most cases
radii = 36:2:144; %144 is half the size of all the images
h = circle_hough(i_edge, radii, 'same', 'normalise');
peaks = circle_houghpeaks(h, radii, 'nhoodxy', 9, 'nhoodr', 9, 'npeaks', 1);

The thing is, some images work fine:

enter image description here enter image description here

But others don't:

enter image description here enter image description here

Here, you can see what I obtain after the line i_edge= edge(image, 'Canny', 0.3); in the first one (finds the circle), and the third (doesn't find the circle). What bothers me the most is that they are more or less similar:

the first image the third image

I tried different kinds of lowpass filters (median, average, gaussian, disk), but with none of them I get better results, rather the opposite.

In the last case, the circle in the edge matrix is almost perfect but still, doesn't find the right circle:

enter image description here

kirchhoff
  • 206
  • 4
  • 12
  • Not a duplicate, I already know how to detect a circle if you read my post. I just want to tweak the algorithm so it works much better, as I need to detect circles in about 110 images and I can't ignore this obvious errors. – kirchhoff May 02 '17 at 14:45
  • Thanks for the edit m7913d. – kirchhoff May 02 '17 at 19:14

1 Answers1

2

Take 3rd figure (ball on green grass), edge detection may fail due to many natural factors like lightning. Here, canny function is enhancing stripes on ball but not its circular edge (this approach may fail as limited to accuracy of edge detection, and what-if edges are not clear).

I suggest following, try to find color clusters (like here will be 2 prominent - green for grass and red for ball) and then raise nearby colors to peak colors (this will evaporate stripes on ball and reduce image colors) before edge detection. Color Clusters may also be used to generate ROI (region of interest) and image can be broken into various regions followed with color grow and circle count.

Its like making entire red ball with black stripes as red ball with red striped and then searching for circles.

SACn
  • 1,862
  • 1
  • 14
  • 29
  • I wonder what would be the computational cost of that. It may be of help so I'm going to upvote your answer as I really apreciate your help. However, I think my problem is more related with the parameters I pass to `circle_houghpeaks`, because `circle_hough` actually contains the right centroid in the returned matrix, it's just the peaks chooses another. – kirchhoff May 02 '17 at 19:27
  • Yes you're right about computational cost. It's out of the context but of relevance. Tools like MATLAB and R are for small scale computations not so well suitable for `image-processing` as cannot par with new `scalable machine learning options`. If it permits have a look parallel libraries: MXNet, Theano, & CNTK they can provide 100x fast mathematical operations on GPU. Only con's is algorithm maybe have to be build from basic blocks, but speed, scalability and future use would improve. – SACn May 04 '17 at 03:53