static BWImage bwLocalMaximaFilter(BWImage img) { int w = img.getWidth(), h = img.getHeight(); BWImage img2 = new(w, h); for y to h: for x to w: img2.setPixel(x, y, 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 img2; }