Ask Your Question

Looking for a thinning/skeletonizing algorithm with opencv in python.

asked 2017-07-03 11:29:16 -0600

bonevale gravatar image

Currently I am implementing the zhang-suen method but my images are 300 ppi and it takes a couple of minutes. Can someone point me in the right direction. I need the skeleton to be connected and there are parallel lines so the the algorithm I've seen in python that uses open and closing is not good. Thanks

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2017-07-03 11:35:36 -0600

berak gravatar image

updated 2017-07-03 11:36:53 -0600

zhang-suen thinning is implemented in opencv_contrib

downside is: if you want to use it, you will have to rebuild your with opencv3 and opencv_contrib

edit flag offensive delete link more


I had a pretty tough time installing opencv the first time around so I am not planning on rebuilding it, however thanks for the suggestion. I am looking more so for pseudo code or an algorithm which I can implement myself if need be.

bonevale gravatar imagebonevale ( 2017-07-07 13:37:19 -0600 )edit

Did you find something for Python? :)

fre2dyy gravatar imagefre2dyy ( 2018-02-13 08:35:31 -0600 )edit

answered 2020-02-05 10:57:17 -0600

You don't have to rebuild to use it. You can simply pip install contrib with: pip install opencv-contrib-python. Then you can simply use zhang-suen thinning implementation like this:

image = cv2.imread("opencv.png")
thinned = cv2.ximgproc.thinning(cv2.cvtColor(image, cv2.COLOR_RGB2GRAY))

If you plot the image before and after you get something like this:

image description

edit flag offensive delete link more

answered 2017-12-01 10:04:57 -0600

A good example of Skeletonization using OpenCV-Python is in

edit flag offensive delete link more


sorry, but that is a link only. not an answer. try harder !

berak gravatar imageberak ( 2017-12-01 10:15:59 -0600 )edit

Question Tools

1 follower


Asked: 2017-07-03 11:29:16 -0600

Seen: 18,829 times

Last updated: Jul 03 '17