A fast thinning algorithm

I'm looking for a fast thinning algorithm that can be readily implemented using OpenCV. The mention of the library is because there are certain things that can be done in a jiffy in say, Mathematica or MATLAB which would require lines of handcode in OpenCV+C.

The algorithm must satisfy the 1 pixel thickness and connectedness criteria.

Has anyone got any experience in implementing one of the tons of available algorithms out there? - Literally spoilt for choice at the sheer number of papers Google threw up. Any pointers in the right direction would do.


Solution 1:

Please check some thinning implementations in my blog:

  1. Zhang-Suen algorithm. (copy on archive.org)
  2. Guo-Hall algorithm. (copy on archive.org)

Both using OpenCV 2.x API.

Solution 2:

for the sake of completeness, I'm posting here a set of thinning algorithms implemented using OpenCV and C/C++ that I found out on the net while answering this question. These have adequately answered this question for my needs. Putting them here in case others have similar requirements.

  1. OpenCV code for thinning (Guo and Hall algo, works with CvMat inputs)
  2. The JR Parker implementation using OpenCV
  3. Possibly more efficient code here (uses OpenCV optimized access methods a lot, however most of the page is in Japanese!)

Solution 3:

I used Zhang-Suen as well Guo-Hall; both produced satisfactory results but not the best ones. Then I tried "A Modified Parallel Thinning Algorithm" by Y. Y. ZHANG and P.S.P Wang. It was far better than the previous two algorithms. Anyone looking for a good thinning algorithm should try it since it is faster and more effective than the other two.

Solution 4:

Not sure if this will help you, but I've used this library and found it very useful, (which includes thinning/skeletonisation). You can download the source here:

http://www.aforgenet.com/framework/

and a good article of its use here:

http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab.aspx