/** * Configures the detector * * @param regionWidthLength How wide the local square region is. * @param tuning Tuning parameter. 0 = standard Otsu. Greater than 0 will penalize zero texture. */ public ThresholdLocalOtsu(boolean otsu2, ConfigLength regionWidthLength, double tuning, double scale, boolean down ) { this.regionWidthLength = regionWidthLength; this.otsu = new ComputeOtsu(otsu2,tuning,down,scale); }
protected void updateHistogramX(int x0, int y0, GrayU8 input) { int indexInput = input.startIndex + y0*input.stride + x0-1; for (int y = 0; y < regionWidth; y++) { histogram[input.data[indexInput] & 0xFF]--; histogram[input.data[indexInput+regionWidth] & 0xFF]++; indexInput += input.stride; } otsu.compute(histogram,histogram.length,numPixels); } protected void updateHistogramY(int x0, int y0, GrayU8 input) {
/** * Computes the threshold and stores the result in the 'threshold' variable * @param histogram * @param length length of histogram * @param totalPixels total sum of all pixels in histogram */ public void compute(int histogram[] , int length , int totalPixels) { if( useOtsu2 ) { computeOtsu2(histogram,length,totalPixels); } else { computeOtsu(histogram,length,totalPixels); } // apply optional penalty to low texture regions variance += 0.001; // avoid divide by zero // multiply by threshold twice in an effort to have the image's scaling not effect the tuning parameter int adjustment = (int)(tuning*threshold*tuning*threshold/variance+0.5); threshold += down ? -adjustment : adjustment; threshold = (int)(scale*Math.max(threshold,0)+0.5); // TODO threshold is a double. REmove rounding? }
protected void updateHistogramY(int x0, int y0, GrayU8 input) { int offset = regionWidth*input.stride; for (int x = 0; x < regionWidth; x++) { int indexInput = input.startIndex + (y0-1)*input.stride + x0+x; histogram[input.data[indexInput] & 0xFF]--; histogram[input.data[indexInput+offset] & 0xFF]++; } otsu.compute(histogram,histogram.length,numPixels); }
/** * Configures the detector * * @param requestedBlockWidth About how wide and tall you wish a block to be in pixels. * @param tuning Tuning parameter. 0 = standard Otsu. Greater than 0 will penalize zero texture. */ public ThresholdBlockOtsu(boolean otsu2, ConfigLength requestedBlockWidth, double tuning, double scale, boolean down, boolean thresholdFromLocalBlocks ) { super(requestedBlockWidth,thresholdFromLocalBlocks,GrayU8.class); this.otsu = new ComputeOtsu(otsu2,tuning,down,scale); stats = new InterleavedS32(1,1,256); }
protected void computeHistogram(int x0, int y0, GrayU8 input) { Arrays.fill(histogram,0); for (int y = 0; y < regionWidth; y++) { int indexInput = input.startIndex + (y0+y)*input.stride + x0; for (int x = 0; x < regionWidth; x++) { histogram[input.data[indexInput++] & 0xFF]++; } } otsu.compute(histogram,histogram.length,numPixels); }
otsu.compute(histogram,histogram.length,total);