public void apply ( GrayU8 binary , int maxLoops ) { this . binary = binary ; inputBorder . setImage ( binary ) ; ones0 . reset ( ) ; zerosOut . reset ( ) ; findOnePixels ( ones0 ) ; for ( int loop = 0 ; ( loop < maxLoops || maxLoops == - 1 ) && ones0 . size > 0 ; loop ++ ) { boolean changed = false ; // do one cycle through all the masks for ( int i = 0 ; i < masks . length ; i ++ ) { zerosOut . reset ( ) ; ones1 . reset ( ) ; masks [ i ] . apply ( ones0 , ones1 , zerosOut ) ; changed |= ones0 . size != ones1 . size ; // mark all the pixels that need to be set to 0 as 0 for ( int j = 0 ; j < zerosOut . size ( ) ; j ++ ) { binary . data [ zerosOut . get ( j ) ] = 0 ; } // swap the lists GrowQueue_I32 tmp = ones0 ; ones0 = ones1 ; ones1 = tmp ; } if ( ! changed ) break ; } }
Applies the thinning algorithm . Runs for the specified number of loops or until no change is detected .