X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=src%2FTests_hough%2FHTCircleMa.m;fp=src%2FTests_hough%2FHTCircleMa.m;h=3afa97f0c6f04104cf9a8f39f132eaa08daeff06;hb=0ff8fb82457bd5a858b2218ab07f69c81323537e;hp=0000000000000000000000000000000000000000;hpb=c6fe9d606eff98fc73b75f23e02a9fd436458ed0;p=master-thesis.git diff --git a/src/Tests_hough/HTCircleMa.m b/src/Tests_hough/HTCircleMa.m new file mode 100644 index 0000000..3afa97f --- /dev/null +++ b/src/Tests_hough/HTCircleMa.m @@ -0,0 +1,41 @@ +% Hough Transform for circles. +% x_dir : the x component of the normalized gradient +% y_dir : the y component of the normalized gradient +% edges : a binary image with edge = 1 +% radius_range is a vector : [min, max] +function [acc_votes, acc_radius] = HTCircleMa(x_dir, y_dir, edges, radius_range) + + [rows, columns] = size(edges); + + acc_votes = zeros(rows, columns); + acc_radius = zeros(rows, columns); + + indexes_edges = find(edges)'; + s = size(edges); + + for r = radius_range(1):radius_range(2) + acc = zeros(rows, columns); + for i = indexes_edges + [y, x] = ind2sub(s, i); + + x0 = round(x + x_dir(i) * r); + y0 = round(y + y_dir(i) * r); + + if x0 < columns && x0 > 0 && y0 < rows && y0 > 0 + acc(y0, x0) = acc(y0, x0) + 1; + end + end + + for x = 1:columns + for y = 1:rows + if acc(y, x) > acc_votes(y, x) + acc_votes(y, x) = acc(y, x); + acc_radius(y, x) = r; + end + end + end + end + + acc_votes = imgaussfilt(acc_votes, 1.0); +end +