Code covered by the BSD License  

Highlights from
Detect lines in grayscale image using Hough Transform

image thumbnail

Detect lines in grayscale image using Hough Transform



02 Dec 2005 (Updated )

Detection of lines (line segments) in a grayscale image using gradient-based Hough Transform.

DrawLines_2Ends(lineseg, varargin)
function DrawLines_2Ends(lineseg, varargin)
%Draw line segments, parameterized as (x1, x2, y1, y2), on graph
%  DrawLines_2Ends(lineseg, varargin)
%  A simple function for drawing line segments on graph. Made as an
%  auxiliary tool for function '[...] = Hough_Grd(...)'.
%  INPUT: (lineseg, properties)
%  lineseg:     Parameters (x1, x2, y1, y2) of line segments to draw.
%               Is a Ns-by-4 matrix with each row contains the parameters
%               (x1, x2, y1, y2) that define the two ends of a line
%               segment. The output 'lineseg' from the function
%               '[...] = Hough_Grd(...)' can be put here directly.
%  properties:  (Optional)
%               A string of line drawing properties. Will be transferred
%               to function 'plot' without modification for line drawing.
%  OUTPUT: None
%  Please send your bug reports, comments and suggestions to
% . Thanks.

%  Author:  Tao Peng
%           Department of Mechanical Engineering
%           University of Maryland, College Park, Maryland 20742, USA
%  Version: alpha       Revision: Dec. 02, 2005

hold on;
for k = 1 : size(lineseg, 1),
    % The image origin defined in function '[...] = Hough_Grd(...)' is
    % different from what is defined in Matlab, off by (0.5, 0.5).
    if nargin > 1,
        plot(lineseg(k,1:2)+0.5, lineseg(k,3:4)+0.5, varargin{1});
        plot(lineseg(k,1:2)+0.5, lineseg(k,3:4)+0.5, 'LineWidth', 2);
hold off;

Contact us