X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2FTests_hough%2FHTCircleGradient.m;fp=src%2FTests_hough%2FHTCircleGradient.m;h=fe20e20c5dbf9ed16dca88729bb7e0c22390eeb6;hb=0ff8fb82457bd5a858b2218ab07f69c81323537e;hp=0000000000000000000000000000000000000000;hpb=c6fe9d606eff98fc73b75f23e02a9fd436458ed0;p=master-thesis.git diff --git a/src/Tests_hough/HTCircleGradient.m b/src/Tests_hough/HTCircleGradient.m new file mode 100644 index 0000000..fe20e20 --- /dev/null +++ b/src/Tests_hough/HTCircleGradient.m @@ -0,0 +1,42 @@ +% Hough Transform for circles with gradient. +% img : gradient image +% radius_range is a vector : [min, max] +function [acc_votes, acc_radius] = HTCircleGradient(img, radius_range) + + [rows, columns] = size(img); + + acc_votes = zeros(rows, columns); + acc_radius = zeros(rows, columns); + + phi_range = linspace(0, 2 * pi, 100); + phi_range(end) = []; + + indexes_non_zero = find(img)'; + s = size(img); + + for r = radius_range(1):radius_range(2) + acc = zeros(rows, columns); + for i = indexes_non_zero + [y, x] = ind2sub(s, i); + for phi = phi_range + x0 = round(x - r * cos(phi)); + y0 = round(y - r * sin(phi)); + if x0 < columns && x0 > 0 && y0 < rows && y0 > 0 + acc(y0, x0) = acc(y0, x0) + img(y, x); + end + 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 +