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.
2 Answers
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["https://i.stack.imgur.com/vWX65.jpg"]
-
1
-
$\begingroup$ Don't forget to follow nikie's link above and upvote that post! $\endgroup$– Jason B.Feb 3, 2016 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$– kirmaFeb 3, 2016 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, 2016 at 15:05 -
$\begingroup$ @JasonB Like most heuristic image processing algorithms, sometimes it works, sometimes not... $\endgroup$– kirmaFeb 3, 2016 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@"https://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:
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}]
-
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$– MarcoBFeb 3, 2016 at 14:37
-
1$\begingroup$ I had to add the ImageAdjust with {0, 0.5, 10} parameters in order to get good results. $\endgroup$ Feb 3, 2016 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$ Feb 3, 2016 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$– MarcoBFeb 3, 2016 at 14:51 -
$\begingroup$ I rewrote my answer with an emphasis on the ImageAdjust $\endgroup$ Feb 3, 2016 at 15:54
ImageAdjust[Import["http://i.stack.imgur.com/vWX65.jpg"], {4.25, -.2}]
as a starting point. $\endgroup$