static BWImage bwLocalMaximaFilter_autoContrast(BWImage img) { int w = img.getWidth(), h = img.getHeight(); float[] f = new[w*h]; int i = 0; for y to h: for x to w: f[i++] = img.getPixel(x, y)- (img.getPixel(x, max(0, y-1)) + img.getPixel(max(0, x-1), y) + img.getPixel(min(w-1, x+1), y) + img.getPixel(x, min(h-1, y+1)))/4; ret iBWAutoContrast(iBWImageFromFloats(w, f)); }