How to make a cleaner copy out of a blurry text image before OCR?

A cleaner copy can be obtained from a blurry original by using the level adjustment in Photoshop before going for a better OCR. The picture below shows an example. My code below failed to do so. What is the appropriate way to get the same job done in Mathematica?

 im = Import ["http://i.stack.imgur.com/BO30x.jpg"];
Manipulate[
adjIm = Dilation[Erosion[Sharpen[im, a], b], c],
Grid[{
{
Control[{{a, 0, "Sharpen"}, 0, 10, Appearance -> "Labeled"} ],
Control[{{b, -1, "Erosion"}, -2, 2, Appearance -> "Labeled"}  ],
},
{
Control[{{c, -1, "Dilation"}, -2, 2, Appearance -> "Labeled"} ],
}
}]
]


Level adjustments can be done with Mathematica using the ImageAdjust function.

But I think Binarizeis good enough for the case you presented. The results are pretty close.

img = Import["http://i.stack.imgur.com/BO30x.jpg"];
img2 = Import["http://i.stack.imgur.com/WhtvY.jpg"];
Grid[{{TextRecognize@Binarize[img, 0.38],
TextRecognize@Binarize[img2]}}]


• If you are using v10, it LocalAdaptiveBinarize may also be worth a check. Sep 7 '14 at 15:56
• LocalAdaptiveBinarize is not really a good idea with such noisy data.
– paw
Sep 7 '14 at 16:03
• It does have parameters which you can adjust, though. Sep 7 '14 at 16:11
• Ah! I didn't know you could set mean and standard diviation.
– paw
Sep 7 '14 at 16:24

The following isn't focused on the Text recognizing part (I'm stealing it from @paw's previous answer) but on separating the ads' text.

img = Import["http://i.stack.imgur.com/BO30x.jpg"];
ib = Binarize@img;
dsc = DeleteSmallComponents[ColorNegate@ib, 500];
sc = SelectComponents[ColorNegate@dsc, "Rectangularity", # > .9 &];

Column[TextRecognize /@
ImageCrop /@ (ImageMultiply[Binarize[img, 0.38], #] & /@
Image /@ (Table[Replace[#, a_ /; (a != i) -> 0, {2}], {i, Range@Max@#}] &@
MorphologicalComponents@sc)), Dividers -> All]