Skip to content

Commit

Permalink
Add function to convert theta, rho from polar space to cartesian spac…
Browse files Browse the repository at this point in the history
…e line
  • Loading branch information
pm3310 committed Oct 28, 2016
1 parent ddaaf30 commit 23cb466
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hough_transform/hough_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def hough_line(img):
return accumulator, thetas, rhos


def polar_space_to_cartesian_space_line(theta, rho):
m = -numpy.cos(theta) / numpy.sin(theta)
b = rho / numpy.sin(theta)

return m, b


if __name__ == '__main__':
# Create binary image and call hough_line
image = numpy.zeros((50, 50))
Expand All @@ -39,3 +46,5 @@ def hough_line(img):
rho = rhos[idx / accumulator.shape[1]]
theta = thetas[idx % accumulator.shape[1]]
print("rho={0:.2f}, theta={1:.0f}".format(rho, numpy.rad2deg(theta)))
m, b = polar_space_to_cartesian_space_line(theta, rho)
print("y = %s * x + %s" % (m, b))

0 comments on commit 23cb466

Please sign in to comment.