I've been trying to implement this paper from Boris Epshtein, Eyal Ofek, and Yonatan Wexler, the pioneers of Stroke Width Transform .

Having a simple image with random texts, that underwent gray scaling. Then I have produced two edge maps using two different algorithms for output comparison (for later) , Sobel and Canny (I'm also planning on Prewwit or other edge detection algorithms). I also have gradient maps x and y, using sobel.

on the segment of computing the gradient direction, given the equation:

theta = arctan( Gy / Gx )


  • theta = is the resulting angle
  • Gx = is the X gradient component
  • Gy = is the Y gradient component
    (both Gx and Gy are from the gradient maps)

I got a bit confused. If the value of Gx is 0 (zero), and we all know dividing by zero is undefined (some say it's infinity), so are we going to make theta infinity or just 0 (zero)?

  • 1
    $\begingroup$ The usual convention on this site is to ask only one question per post. (If you have multiple questions, you can ask them separately.) I edited your post to remove the second question, but you can stil view it by viewing revision history (clicked on "edited...") and ask it separately if you like. Thank you! $\endgroup$ – D.W. Mar 7 '17 at 17:10
  • $\begingroup$ @D.W. I see, sorry about that and Thank you for editing. $\endgroup$ – MrCzeal Mar 7 '17 at 17:20

If $Gx = 0$ and $Gy > 0$, then we use $Gy / 0 = + \infty$. Note that $\arctan +\infty = 1$.

If $Gx = 0$ and $Gy < 0$, then we use $Gy / 0 = -\infty$. Note that $\arctan -\infty = -1$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.