static BufferedImage scaledGrayImageFromBWIntegralImage(int w, BWIntegralImage img) { ret scaledGrayImageFromBWIntegralImage(img, w); } static BufferedImage scaledGrayImageFromBWIntegralImage(BWIntegralImage img, int w, int h default heightForWidth(img.w, img.h, w)) { int w1 = img.w, h1 = img.h; byte[] pixels = new[w*h]; int i = 0; for y to h: for x to w: { // TODO: optimize int x1 = x*w1/w, x2 = max(x1+1, (x+1)*w1/w); int y1 = y*h1/h, y2 = max(y1+1, (y+1)*h1/h); int pixel = iround(img.getPixelAverage(x1, y1, x2, y2)); pixels[i++] = clampToUByte(pixel; } ret newGrayBufferedImage(w, h, pixels); }