From: Peter Bone on
Here's a function for finding circles in a binary edge image using a Hough transform that I need optimizing. I found it on MATLAB central file exchange and then I made it about 10 times faster by making a few changes but it's still too slow because I'm searching a range or circle sizes. So can anyone suggest further optimization? The slowest bit is obviously the first voting part.


function [y0detect,x0detect,Accumulator] = houghcircle(Imbinary,r,thresh)

if nargin == 2
thresh = 4;
elseif thresh < 4
error('treshold value must be bigger or equal to 4');
return
end

%Voting
Accumulator = zeros(size(Imbinary));
rsqr = r^2;
imSize = size(Imbinary);
[yIndex xIndex] = find(Imbinary);
for cnt = 1:length(xIndex)
low=xIndex(cnt)-r;
high=xIndex(cnt)+r;
if (low<1) low=1; end
if (high>imSize(2)) high=imSize(2); end
for x0 = low:high
yOffset = sqrt( rsqr - (xIndex(cnt)-x0)^2 );
y01 = yIndex(cnt) - yOffset;
y02 = yIndex(cnt) + yOffset;
y01 = round(y01); y02 = round(y02);
if y01 < imSize(1) & y01 >= 1
Accumulator(y01,x0) = Accumulator(y01,x0) + 1;
end
if y02 < imSize(1) & y02 >= 1
Accumulator(y02,x0) = Accumulator(y02,x0) + 1;
end
end
end

% Finding local maxima in Accumulator
y0detect = []; x0detect = [];
AccumulatorbinaryMax = imregionalmax(Accumulator);
[Potential_y0 Potential_x0] = find(AccumulatorbinaryMax == 1);
Accumulatortemp = Accumulator - thresh;
for cnt = 1:length(Potential_y0)
if Accumulatortemp(Potential_y0(cnt),Potential_x0(cnt)) >= 0
y0detect = [y0detect;Potential_y0(cnt)];
x0detect = [x0detect;Potential_x0(cnt)];
end
end


Thanks

Peter Bone
 | 
Pages: 1
Prev: CRC16-CCITT checksum code (Error)
Next: USB & FTDI