private BinaryFast thinBinaryRep ( BinaryFast b , int [ ] kernel ) { Point p ; HashSet < Point > inputHashSet = new HashSet < Point > ( ) ; int [ ] [ ] pixels = b . getPixels ( ) ; if ( kernelNo0s ( kernel ) ) { for ( int j = 0 ; j < b . getHeight ( ) ; ++ j ) { for ( int i = 0 ; i < b . getWidth ( ) ; ++ i ) { if ( pixels [ i ] [ j ] == BinaryFast . FOREGROUND ) { inputHashSet . add ( new Point ( i , j ) ) ; } } } } else { Iterator < Point > it = b . getForegroundEdgePixels ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { inputHashSet . add ( it . next ( ) ) ; } } HashSet < Point > result = hitMissHashSet ( b , inputHashSet , kernel ) ; Iterator < Point > it = result . iterator ( ) ; while ( it . hasNext ( ) ) { p = new Point ( it . next ( ) ) ; // make p a background pixel and update the edge sets b . removePixel ( p ) ; b . getForegroundEdgePixels ( ) . remove ( p ) ; b . getBackgroundEdgePixels ( ) . add ( p ) ; // check if new foreground pixels are exposed as edges for ( int j = - 1 ; j < 2 ; ++ j ) { for ( int k = - 1 ; k < 2 ; ++ k ) { if ( p . x + j >= 0 && p . y + k > 0 && p . x + j < b . getWidth ( ) && p . y + k < b . getHeight ( ) && pixels [ p . x + j ] [ p . y + k ] == BinaryFast . FOREGROUND ) { Point p2 = new Point ( p . x + j , p . y + k ) ; b . getForegroundEdgePixels ( ) . add ( p2 ) ; } } } } return b ; }
Takes an image and a kernel and thins it once .