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