Explanation of rho and theta parameters in HoughLines
Asked Answered
F

3

19

Can you give me a quick definition of rho and theta parameters in OpenCV's HoughLines function

void cv::HoughLines (   InputArray  image,
    OutputArray     lines,
    double  rho,
    double  theta,
    int     threshold,
    double  srn = 0,
    double  stn = 0,
    double  min_theta = 0,
    double  max_theta = CV_PI 
)

The only thing I found in the doc is:

rho: Distance resolution of the accumulator in pixels.

theta: Angle resolution of the accumulator in radians.

Do this mean that if I set rho=2 then 1/2 of my image's pixels will be ignored ... a kind of stride=2 ?

Flam answered 10/11, 2016 at 15:39 Comment(1)
It's a kind of stride in the accumulator space, not image space. This is for a 2D histogram. If it was a 1D histogram, it's the same as setting the size of each bin.Geanticlinal
F
32

I have searched for this for hours and still haven't found a place where it is neatly explained. But picking up the pieces, I think I got it.

The algorithm goes over every edge pixel (result of Canny, for example) and calculates ρ using the equation ρ = x * cosθ + y * sinθ, for many values of θ.

The actual step of θ is defined by the function parameter, so if you use the usual math.pi / 180.0 value of theta, the algorithm will compute ρ 180 times in total for just one edge pixel in the image. If you would use a larger theta, there would be fewer calculations, fewer accumulator columns/buckets and therefore fewer lines found.

The other parameter ρ defines how "fat" a row of the accumulator is. With a value of 1, you are saying that you want the number of accumulator rows to be equal to the biggest ρ possible, which is the diagonal of the image you're processing. So if for some two values of θ you get close values for ρ, they will still go into separate accumulator buckets because you are going for precision. For a larger value of the parameter rho, those two values might end up in the same bucket, which will ultimately give you more lines because more buckets will have a large vote count and therefore exceed the threshold.

Some helpful resources:

http://docs.opencv.org/3.1.0/d6/d10/tutorial_py_houghlines.html

https://www.mathworks.com/help/vision/ref/houghtransform.html

https://www.youtube.com/watch?v=2oGYGXJfjzw

Flummery answered 15/9, 2017 at 21:7 Comment(0)
H
1

I know this is a very old post but I wanted to share my findings anyway.

The resolution (of the accumulator) of the output image of the detected lines is basically controlled by ρ (rho) as well as θ (theta) parameters.

Where ρ (rho) is responsible for resolution in terms of pixels. and θ (theta) is responsible for resolution in terms of angels.

low rho value > smaller cells > higher resolution > higher precision detection of lines > higher computation time

Cells: are elements in the accumulator. Each cell has multiple (θ,ρ) values where theta is angle and rho is distance as you already know, coordinates for lines that may exist.

So basically after the computation is done the cells acts as "votes" for a line that might be present and the accumulator is the "voting venue" for cells to vote. The higher the votes on those parameters (θ,ρ), the more likely that there is a line exist on those parameters (θ,ρ).

In conclusion, think of (θ,ρ) as a plane of (x,y) in which it has waves(circles) drawn for each edge pixel and the more they intercept each other on specific points the more like there is a line there.

Left image XY-plane,

  • Orange: A line drawn in an image
  • Green: A point on the orange line
  • Blue: Another point on the orange line

Right Image (θ,ρ) plane,

  • Green: A line drawn from the Green point from the left image (the line represents the green point)
  • Blue: A line drawn from the Blue point from the left image (the line represents the blue point) — Orange: A point resulted from the intersections from green line and blue line.

Image

Horst answered 13/2 at 17:10 Comment(0)
F
0

To detect lines with Hough Transform, the best way is to represents lines with an equation of two parameters rho and theta as shown on this image. The equation is the following :

x cos⁡(θ)+y sin⁡(θ)=ρ

where (x,y) are line parameters.

This writing in (θ,ρ) parameters allow the detection to be less position-depending than a writing as y=a*x+b

(θ,ρ) in this context give the discretization for these two parameters

Hough explanation

Fragile answered 10/11, 2016 at 15:50 Comment(1)
how does this explain anything at allQuantity

© 2022 - 2024 — McMap. All rights reserved.