Binarization, and then thinning/skeletonization I have pictures of networks, like the one below, and my goal is to obtain the network's skeleton from processing those images.



My approach lies in two steps, first I convert grayscale image to binary image using local thresholding or Otsu method, and then a medianfilter (python function medfilt). Result is shown below.



Then, I use a thinning algorithm to extract the network's skeleton.
Here is the result of my implementation of the Zhang-Suen thinning algorithm.



Considering the quality of the first image, I'm pretty sure it's possible to do a lot better than that. I thus have two questions :

1) Taking the last image, how would you remove all the small lines perpendendicular to the ridges, and the small gaps, that are artefacts ?

2) What algorithm would you actually advise me to use for the above mentionned steps (conversion to binary image and thinning) ?

I'm mainly working in python.
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.