Hough Transform - Finding the center of the hough transform circles

9 views (last 30 days)
I have been reading up quite a bit on Hough circles and how it can be used to detect the center and radius of a circular object. Although I understood how the transform works I am still not able to to understand how to get the center of a circle. The code snippet below is customized purely for coins.png in MATLAB. I tried it with a slightly more complex picture and it fails miserably. I am fixing the radius and then getting the accumulator matrix.
Code:
temp = accum;
temp(find(temp<40))=0; %Thresholding
imshow(temp,[0 max(temp(:))])
temp = imdilate(temp, ones(6,6)); %Dilating
imshow(temp,[0 max(max(temp))]);
temp = imerode(temp,ones(3,3)); %Eroding
imshow(temp,[0 max(max(temp))]);
s = regionprops(im2bw(temp),'centroid'); %Computing centroid
centroids = cat(1, s.Centroid);
I wanted to test the code out on a different picture and found this one on google. The Hough Transform produced a favorable result, but it's more overlapping than the previous case and my method fails.
Can someone suggest what the best method is to compute the centroid of the hough circle? I saw a lot of Hough circle transform codes in the Mathworks community, but I couldn't quite figure out how the centroid is being calculated.

Answers (1)

David Young
David Young on 13 Feb 2015
If it helps at all, my version of the FEX circle HTs includes a demo which shows how to get the centres of the circles.
So does the documentation for imfindcircles, which should probably be the function of choice now that it is in the IPT.
Note, by the way, that the HT finds centres rather than centroids. (They are the same if a complete circle is visible, but if only part of the circle is visible the HT finds the actual centre, not the centroid of the visible part.)
If the demos don't help, please could you explain a little more what it is you don't understand - you're clear about how the HT algorithm works, right?
  2 Comments
Mathews John
Mathews John on 14 Feb 2015
I just went through your code. I did to some extend understand what was going on but not all of it. I want to see what would happen if I use imregionalmax. That sounds like an interesting choice of a function.
I know that HTs are supposed to span from an r_min to an r_max, but currently I have fixed the radius value. The trouble with that is instead of getting a local maxima, I essentially end up with smaller circles whose center I have to find. That is where I was getting stuck.
David Young
David Young on 14 Feb 2015
Well it's best to fix the radius value if you know in advance what radius you are looking for, so you may be doing the right thing there. If you are getting smaller circles than you want, then it must mean the radius you are looking for is too small. I'm not sure what you mean by getting small circles instead of a local max though - the local max would be in the accumulator array but the circles are in the image.
I'm not sure what you mean by having to find the centres. Both imfindcircles in the IPT and FEX contributions just give you the centre coordinates as outputs.
My code actually uses imregionalmax in one of the two methods it uses to locate peaks in the accumulator array, so that gives you an example of applying it.
Any help? Can you make your question more exact?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!