Reputation: 5851
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.
Upvotes: 3
Views: 5302
Reputation: 80287
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))
Upvotes: 4
Reputation: 4552
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)
Upvotes: 1