lines = houghlines(BW,theta,rho,peaks)는 영상 BW에서 허프 변환의 특정 Bin과 연결된 선분을 추출합니다. theta와 rho는 함수 hough에서 반환된 벡터입니다. peaks는 houghpeaks 함수에서 반환된 행렬로, 이 행렬에는 선분 탐색 시 사용할 허프 변환 Bin의 행과 열 좌표가 포함되어 있습니다. 반환 값 lines는 추출된 선분에 대한 정보를 포함합니다.
[H,T,R] = hough(BW);
imshow(H,[],'XData',T,'YData',R,...'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
영상의 허프 변환에서 피크를 찾습니다.
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
직선을 찾아 플로팅합니다.
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
endend