# (Matlab) Image processing - Detect multiple circle

• Apr 14th 2009, 05:33 AM
Zoegabh
(Matlab) Image processing - Detect multiple circle
Dear All..

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 =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')

------------------------------------------------------------

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..
• Apr 14th 2009, 10:22 PM
CaptainBlack
Quote:

Originally Posted by Zoegabh
Dear All..

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 =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')

------------------------------------------------------------

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..

Assuming what I think this is doing is correct:

Delete the layer with the already found max, and find the max of the remaining layers.

CB
• Apr 15th 2009, 12:19 AM
Zoegabh
Quote:

Originally Posted by CaptainBlack
Assuming what I think this is doing is correct:

Delete the layer with the already found max, and find the max of the remaining layers.

CB

but i'm still confused about it,
can you explain little bit.
thank you
• Apr 15th 2009, 08:09 AM
CaptainBlack
Quote:

Originally Posted by Zoegabh