Honestly, I had picked up these conditions from OpenCV implementation. Especially, towards the end when I am assigning the value to ``image``, I tried to do it simply by following what they described in the paper. However, that calculation did not yield me appropriate results, so referred to OpneCV implementation. I think I'll revisit these small uncertain conditions and see how the results fare without them. This includes the factor term in ``_grad_func``.