Preparing a photo for the OCR

I want to make grey pixel near to black pixel to be darker. And grey pixel near white pixel become lighter. I also want to make green and red pixel become white. How can I do? Which technique would you prefer? I've tried for weeks but I cannot find an idea that depends upon near pixel and levels and color.


"I think stamp tool is the best solution for your problem." - I think one would get extremely tired after using the stamp tool at the pixel level on a page or two of text. :rolleyes:. You need something more automated.

Getting rid of the color is easy. The easiest approach is to simply desaturate the image, or, if the text is always black or gray, just select pixels with saturation more than 5 or 10% and turn them all white. You can do this using plugins such as Asiva "Select" or an old one called HSB/HSL (that still works fine in CS6) followed by some fiddling around with the S and L channels.

The second half of your question is a lot more involved. Take a look at the image processing operators, "open" and "close", e.g.,

If you are technically / mathematically inclined, for lots good background info on them, go to:

Such operators (including "erode" and "dilate"), are commonly used for tasks like this. Unfortunately, I don't know of any good implementations of them as photoshop plugins or easy image editors. They are certainly available in Matlab and, if memory serves me, Mathematica and also J-image (from NIH). The latter might be the most useful to you.

The only implementation of erode and dilate (no "close" and "open") that I know about in an easy-to-use image editing program is in Photoscape 3.6, but I don't consider their implementation very good / flexible. If anyone knows of good implementations of these operators somewhere else, I would love to hear about it.


Tom M
Last edited:
Here are two examples. The first image is a small crop of your longer document for comparison purposes.

The 2nd image is the same image after using ASIVA Select (mentioned above) twice. First, to change the color of the lighter colored random pixels to white, then, on a 2nd pass to change the color of the darker (but colored) pixels to black.

I'm not at my work computer, so I didn't have access to any of the morphological image transformations mentioned in my earlier post, but I did have Medhi's Flat Median plugin on this computer. It is not as good as the correct mathematical operations, but it does help a bit: You can see that some of the white pixels in the letters are filled in by using it.


Tom M