2

Assume that I have photos of several text documents and presentation slides captured using my smartphone camera. Due to uneven lighting, these photos have color and brightness gradients. Also, the color of the background (paper) in the photo is not pure white (also because of the lighting).

Now, I want to process these photos (preferably with ImageMagick) to look as if it was scanned. A good example of an app that is capable of doing this is CamScanner (on Android and iOS). However, I am looking for a solution to achieve similar results on my Windows PC.

For documents that are black and white, I found a nice ImageMagick script:

magick.exe convert input.png -auto-orient -colorspace gray ( +clone -blur 15,15 ) -compose Divide_Src -composite -normalize -threshold 80% output.png

Source: Batch-processing images of documents to look like a fax

Now, I am looking for a script that can process colored documents (i.e., preserve the color in the output). The corresponding filter in CamScanner would be "Magic Color".

Example:

This input image

input

was fed into CamScanner and this output image

output

was produced. Moreover, I obtained this result with no intervention from my side. I just captured the photo, and the output image was generated automatically.

I am looking for a solution that can do something similar on my Windows computer.

Note: I am not expecting to find an easy solution that would automatically detect the borders and crop accordingly. However, if you know of a solution, please include that as well.

Edit: I experimented with it and found out that -threshold is responsible for making the output image B/W. However, if I don't use -threshold, the resultant image has a 50 times larger filesize (for the input image included as example above). I think that the reason for this is that the image doesn't have a pure white background initially before using the -threshold, which makes the PNG compression less effective. After using the -threshold, the background becomes pure white and, thus, the PNG compression becomes much more effective. So, I am looking for a solution to make the background pure white without causing the image to become B/W.

Also, the clarity of the header row of the table in the output image is not very good regardless of whether I use -threshold or not. So, I am looking for a solution to increase the clarity of the header row (similar to the one achieved using CamScanner).

user
  • 21
  • 2

0 Answers0