linux/xsane scanned at 2700 dpi, 16 bit, 3668 * 2494 color-3.jpg original infrared plane 0color-rgb.jpg original RGB image dirt removal images/steps 1clean-3.jpg infrared plane with reduced red component 2yen-threshold-3.jpg static threshold assuming bimodal histogram 2otsu-threshold-3.jpg static threshold presumed dirt is black, if yen shows less dirt than otsu dirt is not clearly separable by static means 2madmean-threshold-3.jpg adaptive threshold is combined with the yen static threshold to add large dirty areas 3dilate-rgb.jpg dirty pixels are replaced by the nearest clean pixels only replaced pixels are mean filtered 4gamma-rgb.jpg applied gamma 0.4545 for natural appearance gprof.txt gprof output on a Pentium 4, 3.4 GHz, 1 GB RAM actual running time was 13266 ms