X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2FTests_hough%2Ffind_ellipses.m;fp=src%2FTests_hough%2Ffind_ellipses.m;h=4c5e7a0f057066bbbe94e4a57f578d38ce5c93d7;hb=0ff8fb82457bd5a858b2218ab07f69c81323537e;hp=0000000000000000000000000000000000000000;hpb=c6fe9d606eff98fc73b75f23e02a9fd436458ed0;p=master-thesis.git diff --git a/src/Tests_hough/find_ellipses.m b/src/Tests_hough/find_ellipses.m new file mode 100644 index 0000000..4c5e7a0 --- /dev/null +++ b/src/Tests_hough/find_ellipses.m @@ -0,0 +1,60 @@ +function [ellipses] = find_ellipses(acc_votes, acc_radius_1, acc_radius_2, acc_alpha) + if ~exist('acc_radius_2', 'var') + acc_radius_2 = acc_radius_1; + end + + if ~exist('acc_alpha', 'var') + acc_alpha = zeros(size(acc_votes)); + end + + ellipses = {}; % struct('x0', 'y0', 'r1', 'r2', 'alpha') + max_votes = max(acc_votes(:)); + min_votes = min(acc_votes(:)); + threshold_votes = (max_votes - min_votes) * 0.7 + min_votes; + + acc_votes_suppressed = acc_votes; + while true + [votes, index_max] = max(acc_votes_suppressed(:)); + if votes <= threshold_votes + break; + end + + acc_votes_suppressed(index_max) = 0; % Suppress the vote. + + [y, x] = ind2sub(size(acc_votes_suppressed), index_max); + + % If the center ellipse isn't in a known ellipse then add it to 'ellipses'. + accept_ellipse = true; + for i = 1:length(ellipses) + ellipse = ellipses{i}; +% module = sqrt((x - ellipse.x)^2 + (y - ellipse.y)^2); +% phi = asin((y - ellipse.y) / module); +% +% p = [cos(a) -sin(a); sin(a) cos(a)] * [ellipse.r1 * cos(phi); ellipse.r2 * sin(phi)]; +% module_ellipse = sqrt(p(1)^2 + p(2)^2); + + a = ellipse.alpha; + x0 = ellipse.x0; + y0 = ellipse.y0; + r1 = ellipse.r1; + r2 = ellipse.r2; + n = ((x - x0) * cos(a) + (y - y0) * sin(a))^2 / r1^2 + ((x - x0) * sin(a) - (y - y0) * cos(a))^2 / r2^2; + if n <= 1 + accept_ellipse = false; + break; + end + end + + if accept_ellipse + e = struct(... + 'x0', x,... + 'y0', y,... + 'r1', acc_radius_1(index_max),... + 'r2', acc_radius_2(index_max),... + 'alpha', acc_alpha(index_max)); + ellipses{end+1} = e; + fprintf('Ellipse : (x0: %.1f, y0: %.1f, r1: %.1f, r2: %.1f, alpha: %.2f)\n', e.x0, e.y0, e.r1, e.r2, e.alpha); + end + end +end +