Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Related: – nikie Feb 3 at 13:53
ImageAdjust[Import[""], {4.25, -.2}] as a starting point. – JasonB Feb 3 at 14:02
You'll find many useful functions here: – Szabolcs Feb 3 at 14:09
up vote 13 down vote accepted

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_] :=
    ImageData[img]/ImageData[Closing[img, DiskMatrix[5]]]]


enter image description here

share|improve this answer
Great ... incredible – mrz Feb 3 at 14:29
Don't forget to follow nikie's link above and upvote that post! – JasonB Feb 3 at 14:30
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. – kirma Feb 3 at 14:47
@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[""], 23, {0.6, 0.43, 0.25}] – JasonB Feb 3 at 15:05
@JasonB Like most heuristic image processing algorithms, sometimes it works, sometimes not... – kirma Feb 3 at 15:27

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

src = ColorConvert[Import@"", "Grayscale"];
white = Closing[src, DiskMatrix[5]];
imgWithUniformBkg = Image[ImageData[src]/ImageData[white]];

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:

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

enter image description here

share|improve this answer
Gustavo, isn't this exactly the same method, from the same source, with the same implementation shown by Jason in his previous answer above? – MarcoB Feb 3 at 14:37
I had to add the ImageAdjust with {0, 0.5, 10} parameters in order to get good results. – Gustavo Delfino Feb 3 at 14:39
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. – Gustavo Delfino Feb 3 at 14:45
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? – MarcoB Feb 3 at 14:51
I rewrote my answer with an emphasis on the ImageAdjust – Gustavo Delfino Feb 3 at 15:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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