I'm trying to implement the Stroke Width Transform in Python. I have gone through numerous stack overflow questions and answers and other resources on the internet but have not found an implementation for it. So I decided to try on my own.
After performing Canny edge detection, my first step is to calculate the x and y derivatives of the image
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) How do I then combine these to get the gradient at each point in the image? Also, how do I then calculate the width of the stroke?
I'm using the steps given in the original IEEE Paper (freely accessible paper direct from Microsoft here) for reference. The description of the steps is on the bottom of the right hand side on page 3.
xandydirections so you can grab the angle with inverse trig functions (like arctan).atan2(y,x)like I mentioned. The paper discusses how to calculate the stroke width. The basic idea is you start with a pixel in Canny, follow the direction of the gradient until you hit another pixel from Canny. If the gradient direction is opposite, then that's your stroke width, unless either of those pixels has been hit before and stored a lower value.