@Override protected void computeStatistics(GrayU8 input, int innerWidth, int innerHeight) { Arrays.fill(stats.data,0,stats.width*stats.height*256,0); super.computeStatistics(input, innerWidth, innerHeight); }
/** * Applies the dynamically computed threshold to each pixel in the image, one block at a time */ private void applyThreshold( T input, GrayU8 output ) { for (int blockY = 0; blockY < stats.height; blockY++) { for (int blockX = 0; blockX < stats.width; blockX++) { thresholdBlock(blockX,blockY,input,output); } } }
/** * Converts the gray scale input image into a binary image * @param input Input image * @param output Output binary image */ public void process(T input , GrayU8 output ) { InputSanityCheck.checkSameShape(input,output); int requestedBlockWidth = this.requestedBlockWidth.computeI(Math.min(input.width,input.height)); if( input.width < requestedBlockWidth || input.height < requestedBlockWidth ) { throw new IllegalArgumentException("Image is smaller than block size"); } selectBlockSize(input.width,input.height,requestedBlockWidth); stats.reshape(input.width/blockWidth,input.height/blockHeight); int innerWidth = input.width%blockWidth == 0 ? input.width : input.width-blockWidth-input.width%blockWidth; int innerHeight = input.height%blockHeight == 0 ? input.height : input.height-blockHeight-input.height%blockHeight; computeStatistics(input, innerWidth, innerHeight); applyThreshold(input,output); }
/** * Computes the min-max value for each block in the image */ protected void computeStatistics(T input, int innerWidth, int innerHeight) { int statPixelStride = stats.getImageType().getNumBands(); int indexStats = 0; for (int y = 0; y < innerHeight; y += blockHeight) { for (int x = 0; x < innerWidth; x += blockWidth, indexStats += statPixelStride) { computeBlockStatistics(x,y,blockWidth,blockHeight,indexStats,input); } // handle the case where the image's width isn't evenly divisible by the block's width if( innerWidth != input.width ) { computeBlockStatistics(innerWidth,y,input.width-innerWidth,blockHeight,indexStats,input); indexStats += statPixelStride; } } // handle the case where the image's height isn't evenly divisible by the block's height if( innerHeight != input.height ) { int y = innerHeight; int blockHeight = input.height-innerHeight; for (int x = 0; x < innerWidth; x += blockWidth, indexStats += statPixelStride) { computeBlockStatistics(x,y,blockWidth,blockHeight,indexStats,input); } if( innerWidth != input.width ) { computeBlockStatistics(innerWidth,y,input.width-innerWidth,blockHeight,indexStats,input); } } }