static double[][] integralImage_45deg(BufferedImage img) { ret integralImage(new BWImage(img)); } static double[][] integralImage_45deg(BWImage bw) { int w = bw.getWidth(), h = bw.getHeight(); double[][] ii = new double[h][w]; // instead of looking above, we look above to the left // instead of looking left, we look left and down for (int y1 = 0; y1 < h; y++) { double rowSum = 0; for (int x = 0; x <= y1; x++) { int y = y1-x; rowSum += bw.getPixel(x, y); ii[y][x] = y > 0 && x > 0 ? rowSum + ii[y-1][x-1] : rowSum; } } for (int x1 = 1; x1 < w; x1++) { double rowSum = 0; for (int yup = 0; yup < ?; yup++) { int x = x1+yup, y = h-1-yup; rowSum += bw.getPixel(x, y); ii[y][x] = y > 0 && x > 0 ? rowSum + ii[y-1][x-1] : rowSum; } } ret ii; }