HOUGHLINES基于霍夫变换提取线段。行= HOUGHLINES (BW,θ,ρ,山峰)提取图像中的线段BW霍夫变换与特定的垃圾箱。θ和ρ是返回的向量函数的脚腕。矩阵的山峰,HOUGHPEAKS返回的函数,包含的行和列坐标霍夫变换垃圾箱用于寻找线段。HOUGHLINES返回线结构数组的长度等于合并线段发现的数量。结构数组的每个元素有这些字段:point1线段的端点;双元素向量卷帘窗线段的端点;双元素向量θ角(度)的霍夫变换本ρRho-axis Hough变换本端点的位置向量包含(X, Y)坐标。行= HOUGHLINES (VAL1,…, PARAM1 PARAM2, VAL2)设置各种参数。参数名称可以缩写,并不重要。 Each string parameter is followed by a value as indicated below: 'FillGap' Positive real scalar. When HOUGHLINES finds two line segments associated with the same Hough transform bin that are separated by less than 'FillGap' distance, HOUGHLINES merges them into a single line segment. Default: 20 'MinLength' Positive real scalar. Merged line segments shorter than 'MinLength' are discarded. Default: 40 Class Support ------------- BW can be logical or numeric and it must be real, 2-D, and nonsparse. References ---------- Rafael C. Gonzalez, Richard E. Woods, Steven L. Eddins, "Digital Image Processing Using MATLAB", Prentice Hall, 2003 Example ------- % Search for line segments corresponding to five peaks in the Hough % transform of the rotated circuit.tif image. Additionally, highlight % the longest segment. I = imread('circuit.tif'); rotI = imrotate(I,33,'crop'); BW = edge(rotI,'canny'); [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'); % Find lines and plot them 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; end end % highlight the longest line segment plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','cyan'); See also HOUGH, HOUGHPEAKS. Documentation for houghlines doc houghlines