static IBWImage posterizeIBWImage(int brightnessLevels, IBWImage img) { if (brightnessLevels >= 256 || img == null) ret img; int w = img.getWidth(), h = img.getHeight(); ret new IBWImage { public int getWidth() { ret w; } public int getHeight() { ret h; } public float getFloatPixel(int x, int y) { ret (float) quantizeToNLevelsBetweenZeroAndOne_stretch( brightnessLevels, img.getFloatPixel(x, y)); } }; }