Search code examples
c++image-processinghough-transform

why the range of theta is 0~179 when using hough transform for line detection?


I'm trying to use hough-transform for straight line detection. I understand how it works roughly, but there's one thing I can't understand clearly...

in hough-transform, a linear equation changes to r = xcos(theta) + ysin(theta) and every line in image is distinguished by r and theta.

This is what I wonder. when it is implemented in c++,(in the books and many Internet pages..) they change the range of theta 0~359 -> 0~179 and make r has 2*diagonal for storing 180~359theta line.

Is it necessary? theta range decrease by 2 times and r increase 2 times... array[r][theta] has same room after and before that change.

and another question.

enter image description here

in my picture, 1st quadrant is display and red line(in 3rd quadrant)never show in display. ( 2nd or 4th quadrant line can show in display. ) so, is it efficient that theta range has just -90~180 or r has just 3/2*diagonal instead of 2?


Solution

  • To reach maximum coating density you should rotate your line around the center of your image/screen (not the corner).

    So, you should vary theta from 0 to 360 and r from 0 to (diagonal / 2).

    OR, alternatively, you can vary theta from 0 to 180 and r from (-diagonal / 2) to (diagonal / 2), because line with theta = 45 and r = -50 is the same as theta = 135 and r = 50.

    I think in the book they are not bothering with image center (and it is not good) and just rotate the line around the corner (which is natively (0,0) at screen coordinates), so it makes image 2 times bigger. And as they vary theta from 0 to 180 they should vary r from -diagonal to diagonal, that makes intarval size 2*diagonal