1. A method for processing a document image containing background content and foreground content, comprising: (a) generating a foreground mask which is a binary map indicating areas of the document image that contain high values of local features; (b) inpainting the document image in areas indicated by the foreground mask to generate a background map; (c) calculating a difference image between the document image and the background image; and (d) binarizing the difference image to generate a binary foreground image.