I have a scanned image which is basically black print on some weird (non-gray) background, say, green or yellow (think old paper).
How can I get rid of the green/yellow and receive a gray picture with as much of the gray structure of the original image intact? I.e. I want to keep the gray around the letters for the anti-aliasing effect or for gray areas but I want to turn anything which even is remotely green/yellow to become pure white?
Note that the background is by no means homogeneous; so the algorithm should be able accept a color and an error margin or a color range.
For bonus points: How can I automatically determine the background color?
I'd like to use Python with the Imaging Library or maybe ImageMagick.
Note: I'm aware of packages like unpaper. My problem with unpaper is that it produces B&W images which probably look good for an OCR software but not for the human eye.