static double[][] integralImage(BufferedImage img) { ret integralImage(new BWImage(img)); } ifclass RGBImage static double[][] integralImage(RGBImage rgb) { ret integralImage(toBW(rgb)); } endif static double[][] integralImage(BWImage bw) { int w = bw.getWidth(), h = bw.getHeight(); double[][] ii = new double[h][w]; for y to h: { double rowSum = 0; for x to w: { rowSum += bw.getPixel(x, y); ii[y][x] = y > 0 ? rowSum + ii[y-1][x] : rowSum; } } ret ii; }