FYI, I think there is a mistake in your code: https://github.com/halide/CVPR2015/blob/b0cc827573bdf0a22dd0213be64982c32b3b1c86/HoGCamera/jni/edge_detect_generator.cpp#L33 This can be negative, Shouldn't you add 2 * PI to the value atan result when it's negative and do a modulo pi?