public ConfigThresholdLocalOtsu(int regionWidth , double tuning) { this(ConfigLength.fixed(regionWidth),tuning); }
public static ConfigLength relative(double fraction , int minimum ) { return new ConfigLength(minimum,fraction); }
public int computeI( double totalLength ) { double size = compute(totalLength); if( size >= 0 ) return (int)(size+0.5); else return -1; }
@Override protected void detectorProcess(ImageGray input, GrayU8 binary) { // System.out.println("processing image "+count++); binaryToContour.process(binary,labeled); contours = BinaryImageOps.convertContours(binaryToContour); int minContourPixels = minimumContourSize.computeI(Math.min(input.width,input.height)); polylines.clear(); GrowQueue_I32 indices = new GrowQueue_I32(); for (int i = 0; i < contours.size(); i++) { List<Point2D_I32> contour = contours.get(i).external; if( contour.size() < minContourPixels ) continue; if( contourToPolyline.process(contour,indices) ) { List<Point2D_I32> l = new ArrayList<>(); for (int j = 0; j < indices.size; j++) { l.add( contour.get( indices.get(j))); } polylines.add(l); } } }
public ConfigThreshold createConfig() { ConfigThreshold config; if( type == ThresholdType.BLOCK_MIN_MAX) { ConfigThresholdBlockMinMax _config = new ConfigThresholdBlockMinMax(); _config.minimumSpread = minimumSpread; config = _config; } else if( type == ThresholdType.BLOCK_OTSU || type == ThresholdType.LOCAL_OTSU ) { ConfigThresholdLocalOtsu _config = new ConfigThresholdLocalOtsu(); _config.tuning = otsuTuning; _config.useOtsu2 = useOtsu2; config = _config; } else { config = new ConfigThreshold(); config.fixedThreshold = fixedThreshold; } config.type = type; config.scale = scale; config.down = down; config.width = regionWidth.copy(); config.savolaK = savolaK; config.nickK = nickK; config.minPixelValue = minPixelValue; config.maxPixelValue = maxPixelValue; config.thresholdFromLocalBlocks = thresholdLocalBlocks; return config; } }
public void setValue( ConfigLength v ) { // BoofSwingUtil.checkGuiThread(); handleModeChange(v.isRelative(),false); updateValues(v.fraction,v.length); }
/** * 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); }
public void setConfiguration(ConfigThreshold configuration) { comboType.removeActionListener(this); spinnerScale.removeChangeListener(this); buttonUpDown.removeActionListener(this); checkOtsu2.removeActionListener(this); comboType.setSelectedIndex(configuration.type.ordinal()); controlWidth.setValue(configuration.width); spinnerScale.setValue(configuration.scale); buttonUpDown.setSelected(configuration.down); type = configuration.type; regionWidth = configuration.width.copy(); scale = configuration.scale; down = configuration.down; if( type == ThresholdType.FIXED ) { fixedThreshold = (int)configuration.fixedThreshold; } else if( type == ThresholdType.BLOCK_MIN_MAX) { minimumSpread = ((ConfigThresholdBlockMinMax)configuration).minimumSpread; } else if( type == ThresholdType.BLOCK_OTSU || type == ThresholdType.LOCAL_OTSU ) { otsuTuning = (int)((ConfigThresholdLocalOtsu)configuration).tuning; useOtsu2 = ((ConfigThresholdLocalOtsu)configuration).useOtsu2; } comboType.addActionListener(this); spinnerScale.addChangeListener(this); buttonUpDown.addActionListener(this); checkOtsu2.addActionListener(this); updateThresholdValue(); }
public ConfigThresholdBlockMinMax(int width , double minimumSpread, boolean down ) { this(ConfigLength.fixed(width),minimumSpread,down); }
InputSanityCheck.checkSameShape(input, output); regionWidth = regionWidthLength.computeI(Math.min(input.width,input.height));
public ConfigLength copy() { return new ConfigLength(length,fraction); }
this.scale = configThreshold.scale; this.down = configThreshold.down; this.regionWidth = configThreshold.width.copy(); this.savolaK = configThreshold.savolaK; this.nickK = configThreshold.nickK;
public static <T extends ConfigThreshold>T local( ThresholdType type , int width ) { return local(type, ConfigLength.fixed(width)); }
storage2 = InputSanityCheck.checkDeclare(input,storage2,GrayF32.class); int radius = width.computeI(Math.min(input.width,input.height))/2;
public static ConfigLength fixed(double pixels ) { return new ConfigLength(pixels,-1); }
private void setSelection( int which ) { if( which == active ) return; active = which; switch( active ) { case 0 : inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, true, GrayU8.class); break; case 1: inputToBinary = FactoryThresholdBinary.localMean(ConfigLength.fixed(10),0.95,true,GrayU8.class); break; default: throw new RuntimeException("Unknown type"); } }
storage2 = InputSanityCheck.checkDeclare(input,storage2,GrayU8.class); int radius = width.computeI(Math.min(input.width,input.height))/2;
private InputToBinary<GrayU8> createFilter() { int width = this.width + 3; int blockWidth = width*2+4; switch (selectedAlg) { case 0: return FactoryThresholdBinary.globalOtsu(0,255,down,GrayU8.class); case 1: return FactoryThresholdBinary.globalEntropy(0, 255, down, GrayU8.class); case 2: return FactoryThresholdBinary.localMean(ConfigLength.fixed(width),0.95,down,GrayU8.class); case 3: return FactoryThresholdBinary.localGaussian(ConfigLength.fixed(width),0.95,down,GrayU8.class); case 4: return FactoryThresholdBinary.localSauvola(ConfigLength.fixed(width),0.3f,down,GrayU8.class); case 5: return FactoryThresholdBinary.localNick(ConfigLength.fixed(width),-0.2f,down,GrayU8.class); case 6: return FactoryThresholdBinary.blockMean(ConfigLength.fixed(blockWidth),0.95,down,localBlock,GrayU8.class); case 7: return FactoryThresholdBinary.blockMinMax(ConfigLength.fixed(blockWidth),0.95,down,2,localBlock,GrayU8.class); case 8: return FactoryThresholdBinary.blockOtsu(true,ConfigLength.fixed(blockWidth),0,0.95,down,localBlock,GrayU8.class); } throw new RuntimeException("Unknown selection "+selectedAlg); }
storage2 = InputSanityCheck.checkDeclare(input,storage2,GrayU8.class); int radius = width.computeI(Math.min(input.width,input.height))/2;
private void setSelection( int which ) { if( which == active ) return; active = which; synchronized (lockBinarization) { switch (active) { case 0: inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, true, GrayU8.class); break; case 1: inputToBinary = FactoryThresholdBinary.localMean(ConfigLength.fixed(10), 0.95, true, GrayU8.class); break; default: throw new RuntimeException("Unknown type"); } } }