1 function [ellipses] = find_ellipses(acc_votes, acc_radius_1, acc_radius_2, acc_alpha)
2 if ~exist('acc_radius_2', 'var')
3 acc_radius_2 = acc_radius_1;
6 if ~exist('acc_alpha', 'var')
7 acc_alpha = zeros(size(acc_votes));
10 ellipses = {}; % struct('x0', 'y0', 'r1', 'r2', 'alpha')
11 max_votes = max(acc_votes(:));
12 min_votes = min(acc_votes(:));
13 threshold_votes = (max_votes - min_votes) * 0.7 + min_votes;
15 acc_votes_suppressed = acc_votes;
17 [votes, index_max] = max(acc_votes_suppressed(:));
18 if votes <= threshold_votes
22 acc_votes_suppressed(index_max) = 0; % Suppress the vote.
24 [y, x] = ind2sub(size(acc_votes_suppressed), index_max);
26 % If the center ellipse isn't in a known ellipse then add it to 'ellipses'.
27 accept_ellipse = true;
28 for i = 1:length(ellipses)
29 ellipse = ellipses{i};
30 % module = sqrt((x - ellipse.x)^2 + (y - ellipse.y)^2);
31 % phi = asin((y - ellipse.y) / module);
33 % p = [cos(a) -sin(a); sin(a) cos(a)] * [ellipse.r1 * cos(phi); ellipse.r2 * sin(phi)];
34 % module_ellipse = sqrt(p(1)^2 + p(2)^2);
41 n = ((x - x0) * cos(a) + (y - y0) * sin(a))^2 / r1^2 + ((x - x0) * sin(a) - (y - y0) * cos(a))^2 / r2^2;
43 accept_ellipse = false;
52 'r1', acc_radius_1(index_max),...
53 'r2', acc_radius_2(index_max),...
54 'alpha', acc_alpha(index_max));
56 fprintf('Ellipse : (x0: %.1f, y0: %.1f, r1: %.1f, r2: %.1f, alpha: %.2f)\n', e.x0, e.y0, e.r1, e.r2, e.alpha);