File Exchange

image thumbnail

Detect lines in grayscale image using Hough Transform

version 1.0 (423 KB) by

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

21 Ratings



View License

Hough transform for line detection based on image's gradient field.

1. Operates on grayscale images, NOT B/W bitmaps.
2. NO loops involved in the implementation of Hough transform, which makes the operation fast.
3. Able to detect the two ends of line segments.

Comments and Ratings (28)

nice code, please describe with some more excercise


hao (view profile)


I think matlab R2010b fails importing the image as an argument of your function, I used "imread" instead. Nice results, thanks.


xin (view profile)

Great code !The author show us with the parameter
domain with the color image.It's vivid!The result is very fantastic!


Sid (view profile)



Ryan (view profile)


Nitin (view profile)


majid (view profile)

this m code works so well.
but is there any paper ,journal or web page that describe this algorithm?

ole andersen



Manuel (view profile)


Unfortunately the comments are not synchronized with the new input and output parameters. What is 'varargin' and 'varargout'?

James Kerns

Paul Johnson

doesnt work

m f

m f (view profile)

Hey, I was wondering, is it possible to move the point that rho is measured from from the top left corner of the image to the center of the image?


Hi, I'm a 3rd year university student doing an individual project on digital image processing. I need to detect the needle of a dial gauge. I'm new to MATLAB and would like to ask a few questions.

1. I've loaded the Hough_Grd file on to the editor, and loaded it with my image. But how do I view the final resulting image after the line detection? All I see is the matrix numbers.

2. Is there a way to detect specific lines that go through a point?

Sorry if posting my questions here is not appropriate, and thank you for your time.

Fady Soliman

Satisfiable results, was looking for the resulting line coordinates and at last i found it here, thank you very much

Mona Carlos

Vinh Nguyen

yuan xinzhe

venkatesh sathyanaayaa



Tao Peng

Hi, Eugene: "accumarray" is a Matlab function available from versions 7.0 (R14). If you are using an older version of Matlab, that is the problem.

Eugene Kon

Exanples no works!!!!

error message:
??? Undefined function or variable 'accumarray'.

??? Undefined function or variable 'accumarray'.
Error in ==> Hough_Grd.m
On line 260 ==> accum = accumarray( sub2ind(prm_accumsize, sub_rho, sub_theta), ...

David Holden

MATLAB Release
MATLAB 7.0.4 (R14SP2)

Inspired: LoadGaus()

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today