3

I recently started a CV course and am going through old homeworks (the current ones aren't released). I've implemented a Hough Lines function, I loop through each point, if it's an edge, then I loop through 0-180 (or -90 to 90) theta values, and calculate rho, and finally store in an array.

When I tried to convert back from Polar Coordinates, I can find an X,Y pair (using rho * sin(theta), and rho * cos(theta)), however I don't understand how to convert that to a line in Cartesian space. To have a line you need either 2 points or a point and a direction (assuming ray then of course)

I just understand where the point is.

I've done some searching but can't seem to quite find the answer, folks tend to say, polar tells you x, then bam you have a line in cartesian, but I seem to be missing that connection where the "bam" was.

What I mean is described here; Explain Hough Transformation

Also Vector/line from polar coordinates Where it's asked how do I draw a line from polar coords, which the response was well here's x and y. but to me never mentions rest of that solution.

Is the line somehow related to y = mx+b where m is theta and b is rho?

If not how do I convert back to a line in cartesian space.

EDIT: After reviewing Sunreef's answer, and trying to convert so y was on it's own side, I discovered this answer as well: How to convert coordinates back to image (x,y) from hough transformation (rho, theta)?

It appears what I think I'm looking for is this

m = -cotθ

c = p*cosecθ

EDIT#2 I found some other examples on the net. Basically yes I'll need rho * sin(theta) and rho*cos(theta)

The other part that was messing me up was that I needed to convert to radians, once i did that, I started getting good results.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
onaclov2000
  • 5,741
  • 9
  • 40
  • 54

2 Answers2

4

You are right that you can get some base point at the line as

 (X0, Y0) = (rho * cos(theta), rho * sin(theta))

and you can find (unit) direction vector of this line as perpendicular to normal:

(dx, dy) = ( -sin(theta), cos(theta))
MBo
  • 77,366
  • 5
  • 53
  • 86
  • this answer is solid because it is very simple and it illustrates the point that a parallel line with base point (-rho * cos(theta), -rho * sin(theta)), while corresponding to the same point in (r, theta) space as (X0, Y0) above, cannot be the base point of the line in Cartesian space because it does not lie in the positive quadrant – Charles F Apr 24 '17 at 16:13
1

Taken from Wikipedia:

The non-radial line that crosses the radial line ϕ = ɣ perpendicularly at the point (r0, ɣ) has the equation: r(ϕ) = r0 * sec(ϕ - ɣ).

If I suppose that the coordinates you have for your line are ɣ and r0, then you can rewrite this equation like this:

r(ϕ) * cos(ϕ) * cos(ɣ) + r(ϕ) * sin(ϕ) * sin(ɣ) - r0 = 0

And we know that when translating polar to cartesian coordinates, if we have a point P(r, ϕ) in the polar plane, then its coordinates in the cartesian plane will be:

x = r * cos(ϕ)

y = r * sin(ϕ)

So the equation above becomes a line equation as follows:

x * cos(ɣ) + y * sin(ɣ) - r0 = 0

This is the equation of your line in cartesian coordinates.

(Tell me if you see some mistakes, I did that quickly)

Community
  • 1
  • 1
Sunreef
  • 4,452
  • 21
  • 33
  • I'm not recalling off the top of my head if your final equation is right, however I re-arranged things trying to get to y = ... but I think I may have done it wrong, the link I added in my EDIT I managed to find thanks to your answer. – onaclov2000 Aug 24 '16 at 11:46