Hough Transform For Circle Detection - with known radius (I)

This is a very first example that I choose to convert from my previous blog example: http://basic-eng.blogspot.com/2006/01/hough-transform-for-circle-detection.html

The purpose of this example is to detect a circle of known radius from a binary image as follow:

Do note that I am using the latest SCILAB 5.1, and SIVP toolbos 0.5.0. as descripted in my previous post.
For image processing functionalities, the sip tooblox http://siptoolbox.sourceforge.net/ provides more functions, however, for this moment, I am still waiting for the binary version for latest SCILAB for WINDOWS. (please find the http://scilab-imageprocessing.blogspot.com/2009/03/requirement-for-examples-scilab-and.html for the steps of installation)

OK, enought talking, here comes the example:

1. Reading image and the convert to binary image.

I = imread('aaa.png');
I =im2bw(double(I),0.5);

2. Find all the require information for the transformatin. the 'totalpix' is the numbers of '1' in the image.

totalpix = length(x);

3. Preallocate memory for the Hough Matrix. Try to play around with the R, or the radius to see the different results.

HM = zeros(sy,sx);
R = 34;
R2 = R^2;

4. Performing Hough Transform. Notice the accumulator is located in the inner for loop. This portion of codes will map the original image to the a-b domain.

b = 1:sy;

for cnt = 1:totalpix
a = (round(x(cnt) - sqrt(R2 - (y(cnt) - [1:sy]).^2)));
for cnt2 =1:sy
if isreal(a(cnt2),0) & real(a(cnt2))>0
HM(cnt2,real(a(cnt2))) = HM(cnt2,real(a(cnt2))) + 1;

5. Showing the Hough Matrix

imshow(HM); // in binary image

imshow(HM,[]); // in intensity image, so you could notice the max value of Hough Transform

6. Finding the location of the circle with radius of R

[maxval, maxind] = max(max(HM));
[B,A] = find(HM==maxval);
mtlb_hold on;