23

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.

AruniRC
  • 5,070
  • 7
  • 43
  • 73
  • "has anyone got any experience" type questions tend not to be well answered: do you have a more specific question? – James Nov 10 '11 at 16:36
  • @Autopulated: that's true however i *am* asking something a bit vague - there are quite a few fast thinning algorithms, the question is has anyone implemented any using OpenCV and C/C++? – AruniRC Nov 11 '11 at 15:04
  • Hello @AruniRC, do you finally get some satisfactory implementation? – zhy Dec 30 '15 at 06:31

4 Answers4

23

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.

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
flowfree
  • 16,356
  • 12
  • 52
  • 76
11

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!)
Community
  • 1
  • 1
AruniRC
  • 5,070
  • 7
  • 43
  • 73
5

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.

marc1886
  • 148
  • 2
  • 10
  • did you find any implementation or article explaining this modification? Can you elaborate around how much faster it is? – pzo Jan 16 '14 at 22:42
  • If you download the research papers and read through them, you will notice that the Zhang-Wang method does only one iteration and additionally, it has some different conditions to be checked. I processed binary images of size 1600 * 1200. It took approx. 5 sec for Zhang-Suen and approx. 3 sec for Zhang-Wang method. – marc1886 Feb 11 '14 at 14:26
  • Hi Vikramjit, can you share the implementation or describe how you combined the last two conditions? I read the paper but wasn’t sure how to combine the conditions p11=1, p6=0, with conditions p8=0, p15=1 for the modified thinning algorithm. – abe Jun 19 '17 at 01:01
1

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

Jeb
  • 3,689
  • 5
  • 28
  • 45