Hogh Transform
Hogh Transform
MSSV:22151145
Question 1:
1.1.Import an image to Matlab/python/C++
I = imread("art2.png");
imshow(I);title('Original image');
1.3.Hough transform:
*Find the straight line in the edge image
*Show the response of rho and theta value
[H, theta, rho] = hough(I_edges);
peaks = houghpeaks(H, 10);
lines = houghlines(I_edges, theta, rho, peaks);
figure;
subplot(2,1,1), imshow(I), hold on, title('Detected Lines');
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1), xy(:,2), 'LineWidth', 2, 'Color', 'green');
plot(xy(1,1), xy(1,2), 'x', 'LineWidth', 2, 'Color', 'yellow');
plot(xy(2,1), xy(2,2), 'x', 'LineWidth', 2, 'Color', 'red');
end
subplot(2,1,2);
imshow(imadjust(rescale(H)), 'XData', theta, 'YData', rho, ...
'InitialMagnification', 'fit');
xlabel('\theta (degrees)'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(gca,hot);
title('Hough Transform');
Question 2:
2.1.Import an image to Matlab/python/C++
I1 = imread('coins.png');
figure;
imshow(I1);title("Original Image");
2.2.Extract the edge using Canny method
I_edges1 = edge(I1, 'Canny');
figure;
imshow(I_edges1), title('Canny Edge Detection');
2.3.Hough transform:
*Select the radius range of circles
*Find the circles in the edge image
radius_range = [20 50];
[centers, radii] = imfindcircles(I_edges1, radius_range, 'ObjectPolarity', 'bright', 'Sensitivity', 0.9);
figure, imshow(I1), title('Detected Circles');
hold on;
viscircles(centers, radii, 'EdgeColor', 'b');
hold off