static BWImage scaleDownUsingIntegralImageBW(int w, BWIntegralImage img) { ret scaleDownUsingIntegralImageBW(img, w); } static BWImage scaleDownUsingIntegralImageBW(BWIntegralImage img, int w) { ret scaleDownUsingIntegralImageBW(img, w, iround(w*img.h/(double) img.w)); } static BWImage scaleDownUsingIntegralImageBW(BWIntegralImage img, int w, int h) { int w1 = img.w, h1 = img.h; BWImage out = new(w, h); 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 pixel = bwIntegralImage_sumRect(img, x1, y1, x2, y2)/area; out.setByte(x, y, (byte) pixel); } ret out; } static BWImage scaleDownUsingIntegralImageBW(IBWIntegralImage img, int w, int h default iround(w*img.getHeight()/(double) img.getWidth())) { int w1 = img.getWidth(), h1 = img.getHeight(); BWImage out = new(w, h); 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 pixel = bwIntegralImage_sumRect(img, x1, y1, x2, y2)/area; out.setByte(x, y, (byte) pixel); } ret out; }