X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2FTests_hough%2Ftest_hough_ma.m;fp=src%2FTests_hough%2Ftest_hough_ma.m;h=690d3b2c35a3b8f1765a6776595e451428c617df;hb=0ff8fb82457bd5a858b2218ab07f69c81323537e;hp=0000000000000000000000000000000000000000;hpb=c6fe9d606eff98fc73b75f23e02a9fd436458ed0;p=master-thesis.git diff --git a/src/Tests_hough/test_hough_ma.m b/src/Tests_hough/test_hough_ma.m new file mode 100644 index 0000000..690d3b2 --- /dev/null +++ b/src/Tests_hough/test_hough_ma.m @@ -0,0 +1,49 @@ +function test_hough_ma(images_path, image_name) + i = imread([images_path image_name]); + + green = i(:,:,2); + green_filtered = imgaussfilt(green, 1.0); + otsu = ~im2bw(green_filtered, graythresh(green_filtered)); + + se = strel('rectangle', [3 3]); + edges = imdilate(otsu, se) - imerode(otsu, se); + + s = [-1 0 1; -2 0 2; -1 0 1]; + x_edge = conv2(double(green_filtered), s, 'valid'); + y_edge = conv2(double(green_filtered), s', 'valid'); + + magnitudes = sqrt(x_edge .^ 2 + y_edge .^ 2); + + % Unit gradient. + x_dir = x_edge ./ magnitudes; + y_dir = y_edge ./ magnitudes; + + disp('Applying Houg...'); + tic + [acc_votes, acc_radius] = HTCircleMa(x_dir, y_dir, edges(2:end-1, 2:end-1), [25, 35]); + toc + + disp('Finding ellipses...'); + tic + ellipses = find_ellipses(acc_votes, acc_radius); + toc + + name = ['Hough Ma - ' image_name]; + show_figures(name,... + {{green_filtered, 'original filtered with a gaussian, sigma=1'},... + {edges, 'edges (otsu -> dilate - erode)'},... + {expand_matrix(x_edge), 'composante x du gradient'},... + {expand_matrix(acc_votes), 'votes'}}, green, ellipses); + + f = figure; + img = green_filtered; + grayscale = linspace(0, 1, 255); + colormap([grayscale' grayscale' grayscale']); + img(~edges) = 0; + image(img); + axis image; + hold on; + [X, Y] = meshgrid(1:size(green, 2), 1:size(green, 1)); + quiver(X, Y, expand_matrix(x_dir), expand_matrix(y_dir), 'Color', 'yellow'); + savefig(['results/' name ' - gradient.fig']); +end