Automatically remove the background from the photographed text in Photoshop or ImageMagick

    I want to share a trick that helps a little to improve the quality when printing in b / w of any kind of abstract, if for some reason they were "digitized" by the camera instead of the scanner.
    image

    Actually, the main problem with such photos, unlike scans, is the unevenness of the background brightness, sometimes so much so that the text on such a dark background becomes poorly read after printing on a laser b / w printer. As an example of such “unevenness”:
    image

    The idea is to extract something similar to its background from the page and “subtract” it from it, and thereby destroy at least part of the background and brightness variations.

    Get to the point. Suppose we have a couple of dozen photographed in similar conditions of pages. Such a type, but it can be worse:
    image

    Open some of the pages in Photoshop and make a copy of the main layer:
    image

    We invert the top layer: we
    image

    blur it using Gaussian Blur
    image

    ... it’s very important to choose the blur radius correctly: on the one hand it should be larger than the characteristic size of the letters - we need to destroy all the details, on the other hand the too blurry layer will not be able to convey the background gradient, which we are trying to lime. The optimal radius is somewhere around 1.5-3 the size of the row height: it
    image

    remains only to change the method of blending layers, the best thing is what Color Dodge does:
    image

    everything, there is no more gradient:
    image

    you can merge the layers together and twist the brightness and levels to taste (that's all strongly depends on the specific shooting conditions, while the preceding steps are highly universal).

    Now, after practicing, we can proceed to the automation of the process:
    cancel everything that was done with the picture and start recording the macro:
    image

    for recording, repeat everything that was done at the beginning of the article - from cloning the layer to freezing layers and twisting the brightness.
    We stop the macro recording and go to File => Automate => Batch ...
    There we choose where to get pictures of the pages from and where to save them later:
    image

    The process is not very fast, but it is completely automated.
    I hope someone comes in handy, for a long time it’s not relevant.

    UPD: I recommend going through the Unsharp Mask after converging the layers (I used the parameters: radius of 5 pixels / 150%) (c) not_ice

    UPD: the same can be done with ImageMagick , for example, criticism and improvements are welcomed with this command .
    convert.exe src.jpg ( +clone -negate -virtual-pixel edge -gaussian-blur 30x10 ) -background none -compose colordodge -flatten result.jpg



    Also popular now: