@@ -96,6 +96,10 @@ static void thinningIteration(Mat img, int iter, int thinningType){
9696 Mat marker = Mat::zeros (img.size (), CV_8UC1);
9797 int rows = img.rows ;
9898 int cols = img.cols ;
99+ marker.col (0 ).setTo (1 );
100+ marker.col (cols - 1 ).setTo (1 );
101+ marker.row (0 ).setTo (1 );
102+ marker.row (rows - 1 ).setTo (1 );
99103
100104 if (thinningType == THINNING_ZHANGSUEN){
101105 marker.forEach <uchar>([=](uchar& value, const int postion[]) {
@@ -133,6 +137,7 @@ static void thinningIteration(Mat img, int iter, int thinningType){
133137 // int m1 = iter == 0 ? (p2 * p4 * p6) : (p2 * p4 * p8);
134138 // int m2 = iter == 0 ? (p4 * p6 * p8) : (p2 * p6 * p8);
135139 // if (A == 1 && (B >= 2 && B <= 6) && m1 == 0 && m2 == 0) value = 0;
140+ // else value = 1;
136141 });
137142 }
138143 if (thinningType == THINNING_GUOHALL){
@@ -170,6 +175,7 @@ static void thinningIteration(Mat img, int iter, int thinningType){
170175 // int N = N1 < N2 ? N1 : N2;
171176 // int m = iter == 0 ? ((p6 | p7 | (!p9)) & p8) : ((p2 | p3 | (!p5)) & p4);
172177 // if ((C == 1) && ((N >= 2) && ((N <= 3)) & (m == 0))) value = 0;
178+ // else value = 1;
173179 });
174180 }
175181
@@ -183,16 +189,15 @@ void thinning(InputArray input, OutputArray output, int thinningType){
183189 // Enforce the range of the input image to be in between 0 - 255
184190 processed /= 255 ;
185191
186- Mat prev = Mat::zeros (processed.size (), CV_8UC1);
187- Mat diff;
192+ Mat prev = processed.clone ();
188193
189194 do {
190195 thinningIteration (processed, 0 , thinningType);
191196 thinningIteration (processed, 1 , thinningType);
192- absdiff ( processed, prev, diff) ;
197+ if (! hasNonZero ( processed - prev)) break ;
193198 processed.copyTo (prev);
194199 }
195- while (countNonZero (diff) > 0 );
200+ while (true );
196201
197202 processed *= 255 ;
198203
0 commit comments