public ImageRectangle(int x0, int y0, int x1, int y1) { set(x0,y0,x1,y1); }
public IntegralKernel( int numBlocks ) { this.blocks = new ImageRectangle[numBlocks]; this.scales = new int[ numBlocks ]; for( int i = 0; i < numBlocks; i++ ) { blocks[i] = new ImageRectangle(); } }
/** * Computes the fractional area of intersection between the two regions. * * @return number from 0 to 1. higher means more intersection */ public double computeOverlap( ImageRectangle a , ImageRectangle b ) { if( !a.intersection(b,work) ) return 0; int areaI = work.area(); int bottom = a.area() + b.area() - areaI; return areaI/ (double)bottom; }
/** * For the specified regions, computes the values of each fern inside of it and then retrives their P and N values. * The sum of which is stored inside of info. * @param info (Input) Location/Rectangle (output) P and N values * @return true if a known value for any of the ferns was observed in this region */ public boolean lookupFernPN( TldRegionFernInfo info ) { ImageRectangle r = info.r; float rectWidth = r.getWidth(); float rectHeight = r.getHeight(); float c_x = r.x0+(rectWidth-1)/2.0f; float c_y = r.y0+(rectHeight-1)/2.0f; int sumP = 0; int sumN = 0; for( int i = 0; i < ferns.length; i++ ) { TldFernDescription fern = ferns[i]; int value = computeFernValue(c_x, c_y, rectWidth, rectHeight, fern); TldFernFeature f = managers[i].table[value]; if( f != null ) { sumP += f.numP; sumN += f.numN; } } info.sumP = sumP; info.sumN = sumN; return sumN != 0 || sumP != 0; }
/** * Learns a fern from the specified region. No noise is added. */ public void learnFern(boolean positive, ImageRectangle r) { float rectWidth = r.getWidth(); float rectHeight = r.getHeight(); float c_x = r.x0+(rectWidth-1)/2f; float c_y = r.y0+(rectHeight-1)/2f; for( int i = 0; i < ferns.length; i++ ) { // first learn it with no noise int value = computeFernValue(c_x, c_y, rectWidth, rectHeight,ferns[i]); TldFernFeature f = managers[i].lookupFern(value); increment(f,positive); } }
public ImageRectangle( ImageRectangle orig ) { set(orig); }
public IntegralKernel copy() { IntegralKernel ret = new IntegralKernel( blocks.length ); for( int i = 0; i < blocks.length; i++ ) { this.blocks[i] = new ImageRectangle(blocks[i]); this.scales[i] = scales[i]; } return ret; } }
/** * Computes the value for each fern inside the region and update's their P and N value. Noise is added * to the image measurements to take in account the variability. */ public void learnFernNoise(boolean positive, ImageRectangle r) { float rectWidth = r.getWidth(); float rectHeight = r.getHeight(); float c_x = r.x0+(rectWidth-1)/2.0f; float c_y = r.y0+(rectHeight-1)/2.0f; for( int i = 0; i < ferns.length; i++ ) { // first learn it with no noise int value = computeFernValue(c_x, c_y, rectWidth, rectHeight,ferns[i]); TldFernFeature f = managers[i].lookupFern(value); increment(f,positive); for( int j = 0; j < numLearnRandom; j++ ) { value = computeFernValueRand(c_x, c_y, rectWidth, rectHeight,ferns[i]); f = managers[i].lookupFern(value); increment(f,positive); } } }
public static IntegralKernel kernelDerivXY( int size , IntegralKernel ret ) { if( ret == null ) ret = new IntegralKernel(4); int block = size/3; ret.blocks[0].set(-block-1,-block-1,-1,-1); ret.blocks[1].set(0,-block-1,block,-1); ret.blocks[2].set(0, 0, block, block); ret.blocks[3].set(-block-1,0,-1,block); ret.scales[0] = 1; ret.scales[1] = -1; ret.scales[2] = 1; ret.scales[3] = -1; return ret; }
public void mouseDragged(MouseEvent e) { // compute coordinates in the original image int x = (int)(e.getX()/scale); int y = (int)(e.getY()/scale); if( !selected.isInBounds(x,y) ) return; int drawRadius = ((Number) spinnerRadius.getValue()).intValue(); // mark pixels near the selected point ImageRectangle r = new ImageRectangle(x-drawRadius,y-drawRadius,x+drawRadius+1,y+drawRadius+1); BoofMiscOps.boundRectangleInside(selected,r); ImageMiscOps.fillRectangle(selected, (byte)1,r.x0,r.y0,r.x1-r.x0,r.y1-r.y0); // visualize these changes synchronized ( work ) { int color = 0x22FF45; for( int i = r.y0;i < r.y1; i++ ) { for( int j = r.x0; j < r.x1; j++ ) { work.setRGB(j,i,color); } } } repaint((int)(r.x0*scale),(int)(r.y0*scale),(int)((r.x1-r.x0)*scale),(int)((r.y1-r.y0)*scale)); }
public static IntegralKernel kernelDerivYY( int size , IntegralKernel ret ) { if( ret == null ) ret = new IntegralKernel(2); int blockW = size/3; int blockH = size-blockW-1; int r1 = blockW/2; int r2 = blockW+r1; int r3 = blockH/2; ret.blocks[0].set(-r3-1,-r2-1,r3,r2); ret.blocks[1].set(-r3-1,-r1-1,r3,r1); ret.scales[0] = 1; ret.scales[1] = -3; return ret; }
/** * Creates a kernel for a symmetric box derivative. * * @param r Radius of the box. width is 2*r+1 * @return Kernel Kernel for derivative. */ public static IntegralKernel kernelDerivX( int r , IntegralKernel ret ) { if( ret == null ) ret = new IntegralKernel(2); ret.blocks[0].set(-r-1,-r-1,-1,r); ret.blocks[1].set(0,-r-1,r,r); ret.scales[0] = -1; ret.scales[1] = 1; return ret; }
public static IntegralKernel kernelDerivXX( int size , IntegralKernel ret ) { if( ret == null ) ret = new IntegralKernel(2); // lobe size int blockW = size/3; // horizontal band size int blockH = size-blockW-1; int r1 = blockW/2; int r2 = blockW+r1; int r3 = blockH/2; ret.blocks[0].set(-r2-1,-r3-1,r2,r3); ret.blocks[1].set(-r1 - 1, -r3 - 1, r1, r3); ret.scales[0] = 1; ret.scales[1] = -3; return ret; }
/** * Creates a kernel for a symmetric box derivative. * * @param r Radius of the box. width is 2*r+1 * @return Kernel Kernel for derivative. */ public static IntegralKernel kernelDerivY( int r , IntegralKernel ret ) { if( ret == null ) ret = new IntegralKernel(2); ret.blocks[0].set(-r-1,-r-1,r,-1); ret.blocks[1].set(-r-1,0,r,r); ret.scales[0] = -1; ret.scales[1] = 1; return ret; }
/** * Creates a kernel for the Haar wavelet "centered" around the target pixel. * * @param r Radius of the box. width is 2*r * @return Kernel for a Haar x-axis wavelet. */ public static IntegralKernel kernelHaarX( int r , IntegralKernel ret) { if( ret == null ) ret = new IntegralKernel(2); ret.blocks[0].set(-r, -r, 0, r); ret.blocks[1].set(0,-r,r,r); ret.scales[0] = -1; ret.scales[1] = 1; return ret; }
/** * Creates a kernel for the Haar wavelet "centered" around the target pixel. * * @param r Radius of the box. width is 2*r * @return Kernel for a Haar y-axis wavelet. */ public static IntegralKernel kernelHaarY( int r , IntegralKernel ret) { if( ret == null ) ret = new IntegralKernel(2); ret.blocks[0].set(-r,-r,r,0); ret.blocks[1].set(-r,0,r,r); ret.scales[0] = -1; ret.scales[1] = 1; return ret; }
/** * Computes the confidence for all the regions which pass the fern test */ protected void computeTemplateConfidence() { double max = 0; for( int i = 0; i < fernRegions.size(); i++ ) { ImageRectangle region = fernRegions.get(i); double confidence = template.computeConfidence(region); max = Math.max(max,confidence); if( confidence < config.confidenceThresholdUpper) continue; TldRegion r = candidateDetections.grow(); r.connections = 0; r.rect.set(region); r.confidence = confidence; } }
private void addDetections( FastQueue<TldRegion> detections ) { this.detections.reset(); for( TldRegion r : detections.toList() ){ TldRegion a = this.detections.grow(); a.confidence = r.confidence; a.rect.set(r.rect); } }
private void addDetections( FastQueue<TldRegion> detections ) { this.detections.reset(); for( TldRegion r : detections.toList() ){ TldRegion a = this.detections.grow(); a.confidence = r.confidence; a.rect.set(r.rect); } }
o.connections = ra.connections; o.confidence = ra.confidence; o.rect.set(ra.rect); } else if( ra.connections == 0 ) { System.out.println("Not a maximum but has zero connections?");