First we will convert images to greyscale as RGB(x,y)= (R(x,y)+G(x,y)+B(x,y))/3 then, follow these steps:
Based on the “A Fast Parallel Algorithm for Thinning Digital Patterns” by T. Y. Zhang & C.Y. Suen, for each center point P1, it's neighboring cells will be defined by:
We go through all center cells and see which cells to re-color as Black/1 based on these conditions:
-
3 <= B(P1)= P2+P3+P4+P5+P6+P7+P8+9 <= 6
-
A(P1)= 1; center point must be Black/1 itself!
-
FOR EVEN iterations ((x+y)%2==0):
-
P2P4P6=0
-
P4P6P8=0 , where (*) indicates ANDing or multiplying!
-
FOR OLD iterations ((x+y)%2==1):
-
P2P4P8=0
-
P2P6P8=0 , where (*) indicates ANDing or multiplying!
Left/Top trimming before it might help?!
For each center point (P), values are calculated by:
It's easy to create array of nodes where each has X,Y,Type & Types of neighboring cells but somehow I'm running out of heap space here even before comparing! .:. I'm picking the nears X,Y cell with similar type!