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; } static BWImage bwImageTo2Bit(BWImage img) { ret bwImageTo2Bit(0.5f, img); } static BWImage bwImageTo2Bit(float threshold, BWImage img) { ret bwImageTo2Bit(img, threshold); }