private boolean kernelMatch ( Point p , int [ ] [ ] pixels , int w , int h , int [ ] kernel ) { int matched = 0 ; for ( int j = - 1 ; j < 2 ; ++ j ) { for ( int i = - 1 ; i < 2 ; ++ i ) { if ( kernel [ ( ( j + 1 ) * 3 ) + ( i + 1 ) ] == 2 ) { ++ matched ; } else if ( ( p . x + i >= 0 ) && ( p . x + i < w ) && ( p . y + j >= 0 ) && ( p . y + j < h ) && ( ( ( pixels [ p . x + i ] [ p . y + j ] == BinaryFast . FOREGROUND ) && ( kernel [ ( ( j + 1 ) * 3 ) + ( i + 1 ) ] == 1 ) ) || ( ( pixels [ p . x + i ] [ p . y + j ] == BinaryFast . BACKGROUND ) && ( kernel [ ( ( j + 1 ) * 3 ) + ( i + 1 ) ] == 0 ) ) ) ) { ++ matched ; } } } if ( matched == 9 ) { return true ; } else return false ; }
Returns true if the 8 neighbours of p match the kernel 0 is background 1 is foreground 2 is don t care .