question: private static BitMatrix extractPureBits ( BitMatrix image ) throws NotFoundException { int [ ] leftTopBlack = image . getTopLeftOnBit ( ) ; int [ ] rightBottomBlack = image . getBottomRightOnBit ( ) ; if ( leftTopBlack == null || rightBottomBlack == null ) { throw NotFoundException . getNotFoundInstance ( ) ; } float moduleSize = moduleSize ( leftTopBlack , image ) ; int top = leftTopBlack [ 1 ] ; int bottom = rightBottomBlack [ 1 ] ; int left = leftTopBlack [ 0 ] ; int right = rightBottomBlack [ 0 ] ; if ( left >= right || top >= bottom ) { throw NotFoundException . getNotFoundInstance ( ) ; } if ( bottom - top != right - left ) { right = left + ( bottom - top ) ; } int matrixWidth = Math . round ( ( right - left + 1 ) / moduleSize ) ; int matrixHeight = Math . round ( ( bottom - top + 1 ) / moduleSize ) ; if ( matrixWidth <= 0 || matrixHeight <= 0 ) { throw NotFoundException . getNotFoundInstance ( ) ; } if ( matrixHeight != matrixWidth ) { throw NotFoundException . getNotFoundInstance ( ) ; } int nudge = ( int ) ( moduleSize / 2.0f ) ; top += nudge ; left += nudge ; int nudgedTooFarRight = left + ( int ) ( ( matrixWidth - 1 ) * moduleSize ) - right ; if ( nudgedTooFarRight > 0 ) { if ( nudgedTooFarRight > nudge ) { throw NotFoundException . getNotFoundInstance ( ) ; } left -= nudgedTooFarRight ; } int nudgedTooFarDown = top + ( int ) ( ( matrixHeight - 1 ) * moduleSize ) - bottom ; if ( nudgedTooFarDown > 0 ) { if ( nudgedTooFarDown > nudge ) { throw NotFoundException . getNotFoundInstance ( ) ; } top -= nudgedTooFarDown ; } BitMatrix bits = new BitMatrix ( matrixWidth , matrixHeight ) ; for ( int y = 0 ; y < matrixHeight ; y ++ ) { int iOffset = top + ( int ) ( y * moduleSize ) ; for ( int x = 0 ; x < matrixWidth ; x ++ ) { if ( image . get ( left + ( int ) ( x * moduleSize ) , iOffset ) ) { bits . set ( x , y ) ; } } } return bits ; }
target:  This method detects a code in a "pure" image -- that is, pure monochrome image which contains only an unrotated, unskewed, image of a code, with some white border around it. This is a specialized method that works exceptionally fast in this special case.