1 % Hough Transform for circles.
2 % x_dir : the x component of the normalized gradient
3 % y_dir : the y component of the normalized gradient
4 % edges : a binary image with edge = 1
5 % radius_range is a vector : [min, max]
6 function [acc_votes, acc_radius] = HTCircleMa(x_dir, y_dir, edges, radius_range)
8 [rows, columns] = size(edges);
10 acc_votes = zeros(rows, columns);
11 acc_radius = zeros(rows, columns);
13 indexes_edges = find(edges)';
16 for r = radius_range(1):radius_range(2)
17 acc = zeros(rows, columns);
19 [y, x] = ind2sub(s, i);
21 x0 = round(x + x_dir(i) * r);
22 y0 = round(y + y_dir(i) * r);
24 if x0 < columns && x0 > 0 && y0 < rows && y0 > 0
25 acc(y0, x0) = acc(y0, x0) + 1;
31 if acc(y, x) > acc_votes(y, x)
32 acc_votes(y, x) = acc(y, x);
39 acc_votes = imgaussfilt(acc_votes, 1.0);