Search code examples
csiftvlfeat

VLFeat: vlmodulo_2pi_f function


I am trying to understand the inner workings of the VLFeat SIFT algorithm and I notice this statement when computing the image gradient:

 *grad++ = vl_mod_2pi_f   (vl_fast_atan2_f (gy, gx) + 2*VL_PI);

I am wondering if this expression is not the same as vl_fast_atan2_f (gy, gx) as we are adding 2 PI and the modulo of the expression on RHS should evaluate to atan2(gy, gx)?


Solution

  • vl_fast_atan2_f is an approximated (and thus faster) version of atan2 (see this doc for more details).

    Still it returns results in [-pi, pi] so adding 2.pi and take the modulus (vl_mod_2pi_f) rescales the result into [0, 2.pi] which is how the gradient angle is represented.