开发者

efficient line from hough transform coordinates

开发者 https://www.devze.com 2023-04-08 16:56 出处:网络
i\'m working with a hough transform (polar coordinates). i\'d like to compute a vector representation of a line from a coordinate from the hough transform.

i'm working with a hough transform (polar coordinates). i'd like to compute a vector representation of a line from a coordinate from the hough transform.

my current implementation loops through all the pixel coordinates in the image from (0,0) to (M, N) where M and N are the size of the image. as the loop traverses the space, this value is computed:

// angle and rho are the polar coordinates from hough space.

tmp = (int) ( (i * cos( angle ) ) + ( j * sin(angle) ) );

where tmp - rho == 0, is part of the line, so i track that position. when the loop reaches the end of the image (i,j) == (M,N), the loop is done again from the opposite direction (M, N) to (0,0).

the first (tmp-rho == 0) going left to right and the second (tmp-rho == 0) going right开发者_运维百科 to left are the coordinates of the line. i then subtract those pixel coordinates to get a vector of the line in the hough space.

this is terribly inefficient (slow) and i'm 100% sure there's a better way to compute this but, i can't seem to figure it out. any help would be greatly appreciated!


You can solve your equation for i=0, i=M, j=0, j=N instead of looping

rho = i * cos(angle) + j * sin(angle)

i = 0 --> j1 = rho / sin(angle)
i = M --> j2 = (rho - M*cos(angle)) / sin(angle)
j = 0 --> i1 = rho / cos(angle)
j = N --> i2 = (rho - N*sin(angle)) / cos(angle)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号