7
$\begingroup$

I have as example the image below and would like to improve it in such a way that mainly the text is visible and the noisy background is removed.

How can that be done best?enter image description here

$\endgroup$
13
$\begingroup$

Just to make a functional form of nikie's answer, which can't be marked as a duplicate as it's on another SE site,

improve[img_] :=
  ImageCrop@
  Binarize@Image[
    ImageData[img]/ImageData[Closing[img, DiskMatrix[5]]]]

improve@Import["http://i.stack.imgur.com/vWX65.jpg"]

enter image description here

|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ Great ... incredible $\endgroup$ – mrz Feb 3 '16 at 14:29
  • $\begingroup$ Don't forget to follow nikie's link above and upvote that post! $\endgroup$ – Jason B. Feb 3 '16 at 14:30
  • 2
    $\begingroup$ Here might be a good place to point out the existence of LocalAdaptiveBinarize. Its documentation has an example with highly variable text contrast, just in case source material is less than stellar in quality. $\endgroup$ – kirma Feb 3 '16 at 14:47
  • 1
    $\begingroup$ @kirma, I had trouble getting a decent image that way. I used Manipulate like in the example, but I can't get rid of the shading in the corner: LocalAdaptiveBinarize[ Import["http://i.stack.imgur.com/vWX65.jpg"], 23, {0.6, 0.43, 0.25}] $\endgroup$ – Jason B. Feb 3 '16 at 15:05
  • $\begingroup$ @JasonB Like most heuristic image processing algorithms, sometimes it works, sometimes not... $\endgroup$ – kirma Feb 3 '16 at 15:27
5
$\begingroup$

If a grayscale image is needed, we can do as in Jason answer but replacing the binarize with an ImageAdjust.

src = ColorConvert[Import@"http://i.stack.imgur.com/vWX65.jpg", "Grayscale"];
white = Closing[src, DiskMatrix[5]];
imgWithUniformBkg = Image[ImageData[src]/ImageData[white]];
ImageAdjust@imgWithUniformBkg 

But this results in an image that is too light:

enter image description here

A much better results is found after using a manipulate to explore the possible settings:

Manipulate[
    Labeled[ImageAdjust[imgWithUniformBkg, Append[cb, g]], Append[cb, g]], 
    {cb, {-1, -1}, {1, 1}}, {g, 1, 10}]

enter image description here

|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ Gustavo, isn't this exactly the same method, from the same source, with the same implementation shown by Jason in his previous answer above? $\endgroup$ – MarcoB Feb 3 '16 at 14:37
  • 1
    $\begingroup$ I had to add the ImageAdjust with {0, 0.5, 10} parameters in order to get good results. $\endgroup$ – Gustavo Delfino Feb 3 '16 at 14:39
  • 1
    $\begingroup$ Jason answered while I was also writing my response. Yes it is almost the same (mine is not binarized), so I guess that I should delete this answer. $\endgroup$ – Gustavo Delfino Feb 3 '16 at 14:45
  • 1
    $\begingroup$ Whether to delete it or not is of course up to you. Perhaps you could differentiate it further? Your solution returns a grayscale image rather than a black and white one, perhaps you could point that out; maybe your need for ImageAdjust stemmed from there? $\endgroup$ – MarcoB Feb 3 '16 at 14:51
  • $\begingroup$ I rewrote my answer with an emphasis on the ImageAdjust $\endgroup$ – Gustavo Delfino Feb 3 '16 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.