I = imread('ht_test.tif'); im = double(I); BW = edge(im,'canny'); subplot(1,2,2) imshow(BW) [acc,T,R] = hough(BW, 'ThetaResolution', 1, 'RhoResolution', 1); subplot(1,2,1) imshow(log(acc+1), [], 'XData', T, 'YData', R, 'InitialMagnification','fit'); xlabel('\theta'), ylabel('\rho'); axis on, axis normal; P = houghpeaks(acc, 15, 'Threshold', 0.25*max(acc(:)) ); [xs ys] = size(BW); theta = T(P(:,2)); s = R(P(:,1)); sprintf('# of lines found: %d', size(P,1)) for i=1:size(P,1) subplot(1,2,1) hold on plot(theta(i), s(i), 's', 'color', 'red'); hold off subplot(1,2,2); hold on ht_plot( theta(i), s(i), xs, ys ); hold off pause end