clc;
r = imread('C:\Users\lenovo\Desktop\canny.jpg');
t=rgb2gray(r);
figure,imshow(t)
f=edge(t,'canny');
figure,imshow(f)
[H, theta, rho] = hough(f,'RhoResolution',0.5,'Theta',-90:0.5:89.5);
figure
imshow(imadjust(H),'Xdata', theta, 'Ydata', rho, 'InitialMagnification','fit');
axis on, axis normal
p= houghpeaks(H, 5);
%[r,c] = houghpeaks(H, 5);
hold on;
%plot(theta(r), rho(c), 'linestyle', 'none', 'marker', 's', 'color', 'w')
plot(p, 'linestyle', 'none', 'marker', 's', 'color', 'r')
lines = houghlines(f, theta, rho,p);
%lines = houghlines(f, theta, rho, r, c);
figure,
imshow(t)
hold on
for k = 1: length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:, 2), xy(:, 1), 'LineWidth', 4, 'Color', [.6, .2, .1]);
end
hold off
按上面語句試試