1 % Hough Transform for circles.
2 % img : logical image, zeros are the circles edges
3 % radius_range is a vector : [min, max]
4 function [acc_votes, acc_radius] = HTCircle(img, radius_range)
6 [rows, columns] = size(img);
8 acc_votes = zeros(rows, columns);
9 acc_radius = zeros(rows, columns);
11 phi_range = linspace(0, 2 * pi, 100);
14 indexes_non_zero = find(img)';
17 for r = radius_range(1):radius_range(2)
18 acc = zeros(rows, columns);
19 for i = indexes_non_zero
20 [y, x] = ind2sub(s, i);
22 x0 = round(x - r * cos(phi));
23 y0 = round(y - r * sin(phi));
24 if x0 < columns && x0 > 0 && y0 < rows && y0 > 0
25 acc(y0, x0) = acc(y0, x0) + 1;
32 if acc(y, x) > acc_votes(y, x)
33 acc_votes(y, x) = acc(y, x);
40 acc_votes = imgaussfilt(acc_votes, 1.0);