Binarization, and then thinning/skeletonization
Your implementation of the ZS algorithm is wrong. The correct output should be:


Here you can see the output superimposed on the original binary image:


Removing the small branches would require a little more effort and is not exactly off the shelf, but basically you could tag every segment between junction points and end points with its length and prune the ones which are too short. Then you can also take into account the "main" direction and not prune in that direction.