static BWImage bwImageTo2Bit(BWImage img, float threshold) { int w = img.w(), h = img.h(); BWImage img2 = new BWImage(w, h); for y to h: for x to w: img2.setPixel(x, y, img.getPixel(x, y) >= threshold ? 1f : 0f); ret img2; }