static BufferedImage scaledBufferedImageFromIntegralImage(int w, IntegralImage img) { ret scaledBufferedImageFromIntegralImage(img, w); } static BufferedImage scaledBufferedImageFromIntegralImage(IntegralImage img, int w) { ret scaledBufferedImageFromIntegralImage(img, w, rowsForColsWithAspectRatio(w, img.w, img.h)); } static BufferedImage scaledBufferedImageFromIntegralImage(int w, int h, IntegralImage img) { ret scaledBufferedImageFromIntegralImage(img, w, h); } static BufferedImage scaledBufferedImageFromIntegralImage(IntegralImage img, int w, int h) { int w1 = img.w, h1 = img.h; int[] pixels = new[w*h]; int i = 0; for y to h: for x to w: { 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 area = (x2-x1)*(y2-y1); int r = integralImage_sumRect(img, x1, y1, x2, y2, 0)/area; int g = integralImage_sumRect(img, x1, y1, x2, y2, 1)/area; int b = integralImage_sumRect(img, x1, y1, x2, y2, 2)/area; pixels[i++] = 0xFF000000 | (r << 16) | (g << 8) | b; } ret intArrayToBufferedImage(pixels, w, h); }