static BufferedImage grayImageFromIBWImage(IBWImage img) { int w = img.getWidth(), h = img.getHeight(); byte[] pixels = new[w*h]; int i = 0; for y to h: for x to w: { int pixel = iround(img.getFloatPixel(x, y)*255); // tODO: is it round or floor? ifdef grayImageFromIBWIntegralImage_debug if (x == 0 && y == 0) print(+pixel); endifdef pixels[i++] = clampToUByte(pixel; } ret newGrayBufferedImage(w, h, pixels); }