static BWImage iBWAutoContrast(IBWImage bw) { ret iBWAutoContrast(bw, 0f); } // def value is usually irrelevant static BWImage iBWAutoContrast(IBWImage bw, float def) { if (bw == null) null; int w = bw.getWidth(), h = bw.getHeight(); float min = 1, max = 0; for y to h: for x to w: { float f = bw.getFloatPixel(x, y); min = min(min, f); max = max(max, f); } if (min == max) ret new BWImage(w, h, def); float factor = floatRatio(1, max-min); BWImage bw2 = new BWImage(w, h); for y to h: for x to w: bw2.setPixel(x, y, (bw.getFloatPixel(x, y)-min)*factor); ret bw2; }