computeHistogram(0,0,input); applyToBlock(0,0,x0+1,y0+1,input,output); updateHistogramX(x-x0,0,input); applyToBlock(x,0,x+1,y0,input,output); updateHistogramX(x1-x0,0,input); applyToBlock(x1,0,input.width,y0+1,input,output); updateHistogramY(x1-x0,y-y0,input); applyToBlock(x1,y,input.width,y+1,input,output); updateHistogramY(x1-x0,y1-y0,input); applyToBlock(x1,y1,input.width,input.height,input,output); computeHistogram(0,0,input); updateHistogramY(0,y-y0,input); applyToBlock(0,y,x0,y+1,input,output); updateHistogramY(0,y1-y0,input); applyToBlock(0,y1,x0+1,input.height,input,output); updateHistogramX(x-x0,y1-y0,input); applyToBlock(x,y1,x+1,input.height,input,output);
int indexOutput = output.startIndex + y*output.stride + x0; computeHistogram(0,y-y0,input); output.data[indexOutput++] = (input.data[indexInput++]&0xFF) <= otsu.threshold ? a : b; updateHistogramX(x-x0,y-y0,input); output.data[indexOutput++] = (input.data[indexInput++]&0xFF) <= otsu.threshold ? a : b; applyToBorder(input, output, y0, y1, x0, x1);
/** * Applies a local Otsu threshold * * @see ThresholdLocalOtsu * * @param scale Scale factor adjust for threshold. 1.0 means no change. * @param down Should it threshold up or down. * @param regionWidth About how wide and tall you wish a block to be in pixels. * @param inputType Type of input image * @return Filter to binary */ public static <T extends ImageGray<T>> InputToBinary<T> localOtsu(boolean otsu2, ConfigLength regionWidth , double tuning, double scale, boolean down, Class<T> inputType) { if( BOverrideFactoryThresholdBinary.localOtsu != null ) return BOverrideFactoryThresholdBinary.localOtsu.handle(otsu2,regionWidth, tuning, scale, down, inputType); return new InputToBinarySwitch<>(new ThresholdLocalOtsu(otsu2,regionWidth,tuning,scale,down),inputType); }