next up previous
Next: Make Use of Up: hough Previous: Definition

Straight Line Detection

A straight line in 2D space described by this parametric equation:

\begin{displaymath}
f(x,y,\rho_0,\theta_0)=x\; cos\; \theta_0 + y\; sin\; \theta_0 -\rho_0 = 0
\end{displaymath}

can be represented in the 2D parameter space by a point $(\rho_0, \theta_0)$, where $\rho_0$ is the distance between the straight line and the origin, and $\theta_0$ is the angle between the distance vector and the positive x-direction.

hough_2c.gif hough_2b.gif

To find the Hough transform of a certain point $(x_0,y_0)$ in the image space, we solve the equation above for $\rho$ and get

$\displaystyle \rho$ $\textstyle =$ $\displaystyle x_0\; cos \;\theta + y_0\; sin\; \theta
= \sqrt{x_0^2+y_0^2}\;\; ...
...rt{x_0^2+y_0^2}}\;cos\; \theta
+ \frac{y_0}{\sqrt{x_0^2+y_0^2}}\; sin\; \theta)$  
  $\textstyle =$ $\displaystyle r_0\; (cos\; \alpha_0\; cos\; \theta + sin\; \alpha_0\; sin\; \theta)
= r_0\; cos (\alpha_0-\theta)$  

where

\begin{displaymath}\left\{ \begin{array}{l}
r_0 \stackrel{\triangle}{=} \sqrt{...
...stackrel{\triangle}{=} tan^{-1} (y_0/x_0)
\end{array} \right. \end{displaymath}

The ddetection of all straight lines in the image can be carried out by the following steps:

  1. Make available an $n=2$ dimensional array $H(\rho,\theta)$ for the parameter space;
  2. Find the gradient image: $G(x,y)=\vert G(x,y)\vert \angle G(x,y)$;
  3. For any pixel satisfying $\vert G(x,y)\vert > T_s$, increment all elements on the sinusoidal curve $\rho=x\; cos\; \theta + y\; sin\; \theta$ in the parameter space represented by the H array:

    for all $\theta$ {

    \begin{displaymath}\rho=x\; cos\; \theta + y\; sin\; \theta; \end{displaymath}


    \begin{displaymath}H(\rho, \theta)=H(\rho, \theta)+1; \end{displaymath}

    }

  4. In the parameter space, any element $H(\rho, \theta) > T_h$ represents a straight line detected in the image.

This algorithm can be improved by making use of the gradient direction $\angle G$, which, in this particular case, is the same as the angle $\theta$. Now for any point $\vert G(x,y)\vert > T_s$, we only need to increment the elements on a small segment of the sinusoidal curve. The third step in the above algorithm can be modified as:

  1. (same as above)
  2. (same as above)
  3. For any pixel satisfying $\vert G(x,y)\vert > T_s$,

    for all $\theta$ satisfying $\angle G(x, y)-\Delta \theta \leq \theta \leq \angle G(x, y)+\Delta \theta$

    {

    \begin{displaymath}\rho=x\; cos\; \theta + y\; sin\; \theta; \end{displaymath}


    \begin{displaymath}H(\rho, \theta)=H(\rho, \theta)+1; \end{displaymath}

    }

    where $\Delta \theta$ defines a small range in $\theta$ to allow some room for error in $\angle G$.

  4. (same as above)

Check out this online demo.


next up previous
Next: Make Use of Up: hough Previous: Definition
Ruye Wang 2009-11-17