
Originally Posted by
Zoegabh
Dear All..
I need your help about hough transform..
I have problem with detecting multiple circle
I have program to detect a circle and show the radius of it..
but the problem is I want to detect another circle in a picture and shown the radius as well..
here is the program
---------------------------------------------------------------------
%circle equation = (x-a)^2 + (y-b)^2 = R^2
I = imread('pic23.bmp');
% function [radian]= hough (I)
I =im2bw(I);
[y,x]=find(I);
[sy,sx]=size(I);
totalpix = length(x); %totalpix is the numbers of '1' in the image (white)
HM = zeros(sy,sx,50); %Preallocate memory
R = 1:50; %R is known in the range from 1 to 50
R2 = R.^2;
sz = sy*sx; %column x row
% Hough Transform
for cnt = 1:totalpix
for cntR = 1:50
b = 1:sy;
a = (round(x(cnt) - sqrt(R2(cntR) - (y(cnt) - [1:sy]).^2))); %(x-a)^2 + (y-b)^2 = R^2
b = b(imag(a)==0 & a>0);
a = a(imag(a)==0 & a>0);
ind = sub2ind([sy,sx],b,a);
HM(sz*(cntR-1)+ind) = HM(sz*(cntR-1)+ind) + 1;
end
end
% Find for the maximum value for each layer, or in other words, the layer
% with maximum value will indicate the correspond R for the circle
for cnt = 1:50
H(cnt) = max(max(HM(:,:,cnt)));
end
[maxval, maxind] = max(H);
[B,A] = find(HM(:,:,maxind)==maxval);
imshow(I); hold on;
plot(mean(A),mean(B),'xr')
text(mean(A),mean(B),num2str(maxind),'color','gree n')
radian = maxind
------------------------------------------------------------
and the result of the image i put on attachment .
It shows only the radius of the biggest circle.
I want to know the small one also, or if there is another circle.
Thank you very much for any help..