Introduction
The next step is to implement the thinning algorithm, where we use the zhang-suen thinning algorithm. This method aims to remove all the points until becoming a single line (skeleton).
The algoritmh check all colored points (will call black), then see if the neighbor’s black and white is under some condition, if the condition mets the black point would be removed (that is become white).
Implementation
CountNonZero8(result asA)
- count how many
1’s in the 8 neighbors.
Transitions01(results asB)
- count how many
0to1for 8 neighbors.
- Two pass checking (slightly differnet)
Ashould be2~6Bshould be1p2orp4orp6should be0(p2,p4,p8in second pass)p4orp6orp8should be0(p2,p6,p8in second pass)
denoting as:
p9 p2 p3
p8 p1 p4
p7 p6 p5
Intuition
the intuition for the B to become one is that B means for that point’s neighbor, how many groups did they formed.
If B is 0 that means this point is isolated, if B is 1 that means removing this point would not affect the connection topology. For larger than 2, it means that removing would make it unconencted
1 1 1 1 1 1 1 1 1
1 1 0 0 1 0 0 1 0
1 0 0 0 1 1 1 0 1
< B = 1 > < B = 2 > < B = 3 >
For the two-pass checking part, it is seperated into two different direction to avoid removing a 2-pixel wide structure.
1 1 becomes 0 0
1 1 ----------> 0 0
1 1 0 0