Skip to content

Instantly share code, notes, and snippets.

@paramaggarwal
Created January 26, 2017 11:50
Show Gist options
  • Save paramaggarwal/f0880c2ad63c06da6ca1cf3cc8ec926a to your computer and use it in GitHub Desktop.
Save paramaggarwal/f0880c2ad63c06da6ca1cf3cc8ec926a to your computer and use it in GitHub Desktop.
A small guide to Hough Transform

How to build an intuition for the various parameters in Hough Transform?

The rho and theta units are part of the Hough Transform, but the value we give here specifies the imaginary grid that we create in this transformed domain. For example in the threshold parameter, we say that each grid box should have atleast x intersections. So the grid itself is defined by these parameters.

In the hough transform, the x and y coordinates become rho and theta. To be able to define imaginary boxes in this space, I need to give a width and height to them. This will be the rho and theta values in this domain. And then in the next parameter I say, “Hey, now in each of these rectangular imaginary boxes, you should see atleast N number of interections - if so, then it is a line."

It allows us to specify the straightness of a line. As in, should a slightly curved line also be a line? If a line is curving, all the corresponding hough lines won’t intersect perfectly. So by specifying a large imaginary box, we are able to say - “It’s ok if the lines don’t intersect precisely - just see that the intersections are close to each other.

  1. threshold: Number of intersections in hough space boxes defined by rho and theta
  2. min_line_length: In cartesian space, the min length of a continuous dots to be considered a valid line
  3. max_line_gap: How much gap between points is forgiven to still consider them part of same line.

Important thing to note here, the lines in Hough space are generally curved - see the lesson quizes to build your intuition on this. With rho and theta, we are not defining just one box, but a grid. Each cell in the grid has a width and height as defined by rho and theta.

Now we find which of these boxes have line intersections above the threshold. Next, a Hough space point in the center of this grid/box will transform to a line in the Image Space. We filter the lines in the image space, which are below the min_line_length and then we connect the lines which are only separated by a gap no longer than max_line_gap. If rho=1 and theta=pi/180, there's only 1 bin in Hough space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment