0
votes

Here is the example Hough Transform from the CImg library

I'm trying to figure out how this implementation works, since it is so much different from the other ones you might find online.

As I understand it, for a Hough transform you need to loop through every edge point and calculate 180 degrees of rho/theta values to populate the field.

But in the CImg implementation, when you press space, the programs just loops through every pixel and calculates the rho/theta once and in the end it still generates a correct result.

I'm trying to implement this on my own without the aid of any libraries but I can't figure out how this works. I think the "magic" happens between the 2 gradient images taken before the loop, but I can't seem to figure it out.

Can anyone point me in the right direction?

1

1 Answers

0
votes
double
  gx = grad[0](x,y),
  gy = grad[1](x,y);
double
  theta = std::atan2(gy,gx);

Calculates the direction of the gradient. This way we get the theta without looping through 180° for each point.

I think it's basically a Sobel operation:

https://en.m.wikipedia.org/wiki/Sobel_operator