@Override public void computeHistogram(final int x, final int y, final int w, final int h, final Histogram hist) { final int x2 = x + w; final int y2 = y + h; final double[] values = hist.values; for (int i = 0; i < values.length; i++) { final float val = sats[i].calculateArea(x, y, x2, y2); values[i] = Math.max(0, val); // rounding errors in the SAT // might lead to small -ve's } }
@Override public void computeHistogram(final int x, final int y, final int w, final int h, final Histogram hist) { final int x2 = x + w; final int y2 = y + h; final double[] values = hist.values; for (int i = 0; i < values.length; i++) { final float val = sats[i].calculateArea(x, y, x2, y2); values[i] = Math.max(0, val); // rounding errors in the SAT // might lead to small -ve's } }
/** * Calculate the sum of pixels in the image used for constructing this SAT * within the given rectangle * * @param r * rectangle * @return sum of pixels in given rectangle */ public float calculateArea(Rectangle r) { return calculateArea(Math.round(r.x), Math.round(r.y), Math.round(r.x + r.width), Math.round(r.y + r.height)); }
/** * Calculate the sum of pixels in the image used for constructing this SAT * within the given rectangle * * @param r * rectangle * @return sum of pixels in given rectangle */ public float calculateArea(Rectangle r) { return calculateArea(Math.round(r.x), Math.round(r.y), Math.round(r.x + r.width), Math.round(r.y + r.height)); }
@Override public Histogram computeHistogram(final int x, final int y, final int w, final int h) { final Histogram hist = new Histogram(nbins); final int x2 = x + w; final int y2 = y + h; for (int i = 0; i < nbins; i++) { final float val = sats[i].calculateArea(x, y, x2, y2); // rounding errors in the SAT can lead to small values that should // actually be zero hist.values[i] = val < 1e-4 ? 0 : val; } return hist; }
@Override public Histogram computeHistogram(final int x, final int y, final int w, final int h) { final Histogram hist = new Histogram(nbins); final int x2 = x + w; final int y2 = y + h; for (int i = 0; i < nbins; i++) { final float val = sats[i].calculateArea(x, y, x2, y2); // rounding errors in the SAT can lead to small values that should // actually be zero hist.values[i] = val < 1e-4 ? 0 : val; } return hist; }
final float scale = 1.0f / (xMax - xMin) / bh; pixels[y][x] = sat.calculateArea(xMin, yMin, xMax, yMax) * scale;
final float scale = 1.0f / (xMax - xMin) / bh; pixels[y][x] = sat.calculateArea(xMin, yMin, xMax, yMax) * scale;
@Override public void processImage(FImage image) { // shortcut trivial case if (this.height == 1 && this.width == 1) return; final SummedAreaTable sat = new SummedAreaTable(); sat.analyseImage(image); final int hw = width / 2; final int hh = height / 2; for (int y = 0; y < image.height; y++) { for (int x = 0; x < image.width; x++) { final int sx = Math.max(0, x - hw); final int sy = Math.max(0, y - hh); final int ex = Math.min(image.width, x + hw + 1); final int ey = Math.min(image.height, y + hh + 1); final float mean = sat.calculateArea(sx, sy, ex, ey); image.pixels[y][x] = mean; } } } }
@Override public void processImage(FImage image) { // shortcut trivial case if (this.height == 1 && this.width == 1) return; final SummedAreaTable sat = new SummedAreaTable(); sat.analyseImage(image); final int hw = width / 2; final int hh = height / 2; for (int y = 0; y < image.height; y++) { for (int x = 0; x < image.width; x++) { final int sx = Math.max(0, x - hw); final int sy = Math.max(0, y - hh); final int ex = Math.min(image.width, x + hw + 1); final int ey = Math.min(image.height, y + hh + 1); final float mean = sat.calculateArea(sx, sy, ex, ey); image.pixels[y][x] = mean; } } } }
@Override public void processImage(FImage image) { // shortcut trivial case if (this.height == 1 && this.width == 1) return; final SummedAreaTable sat = new SummedAreaTable(); sat.analyseImage(image); final int hw = width / 2; final int hh = height / 2; for (int y = 0; y < image.height; y++) { for (int x = 0; x < image.width; x++) { final int sx = Math.max(0, x - hw); final int sy = Math.max(0, y - hh); final int ex = Math.min(image.width, x + hw + 1); final int ey = Math.min(image.height, y + hh + 1); final int area = (ex - sx) * (ey - sy); final float mean = sat.calculateArea(sx, sy, ex, ey) / area; image.pixels[y][x] = mean; } } } }
@Override public void processImage(FImage image) { // shortcut trivial case if (this.height == 1 && this.width == 1) return; final SummedAreaTable sat = new SummedAreaTable(); sat.analyseImage(image); final int hw = width / 2; final int hh = height / 2; for (int y = 0; y < image.height; y++) { for (int x = 0; x < image.width; x++) { final int sx = Math.max(0, x - hw); final int sy = Math.max(0, y - hh); final int ex = Math.min(image.width, x + hw + 1); final int ey = Math.min(image.height, y + hh + 1); final int area = (ex - sx) * (ey - sy); final float mean = sat.calculateArea(sx, sy, ex, ey) / area; image.pixels[y][x] = mean; } } } }
@Override public void processCorrelationMap(FImage img, FImage template, FImage corr) { SummedAreaTable sum = new SummedAreaTable(); img.analyseWith(sum); final float templateMean = FloatArrayStatsUtils.mean(template.pixels); //TODO: cache this final float[][] pix = corr.pixels; for( int y = 0; y < corr.height; y++ ) { for( int x = 0; x < corr.width; x++ ) { double num = pix[y][x]; double t = sum.calculateArea(x, y, x+template.width, y+template.height); num -= t * templateMean; pix[y][x] = (float)num; } } } },
@Override public void processCorrelationMap(FImage img, FImage template, FImage corr) { SummedAreaTable sum = new SummedAreaTable(); img.analyseWith(sum); final float templateMean = FloatArrayStatsUtils.mean(template.pixels); //TODO: cache this final float[][] pix = corr.pixels; for( int y = 0; y < corr.height; y++ ) { for( int x = 0; x < corr.width; x++ ) { double num = pix[y][x]; double t = sum.calculateArea(x, y, x+template.width, y+template.height); num -= t * templateMean; pix[y][x] = (float)num; } } } },
sat.calculateArea(xR, yR, xR + hw, yR + hh), sat.calculateArea(xR + hw, yR, xR + widthR, yR + hh), sat.calculateArea(xR, yR + hh, xR + hw, yR + heightR), sat.calculateArea(xR + hw, yR + hh, xR + widthR, yR + heightR), };
sat.calculateArea(xR, yR, xR + hw, yR + hh), sat.calculateArea(xR + hw, yR, xR + widthR, yR + hh), sat.calculateArea(xR, yR + hh, xR + hw, yR + heightR), sat.calculateArea(xR + hw, yR + hh, xR + widthR, yR + heightR), };