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
  • What happens if you just omit `-colorspace gray`? – Tetsujin Mar 25 '23 at 13:04
  • @Tetsujin By omitting `-colorspace gray`, I get a result similar to the one I get by including that. However, I also get the following error message in cmd `convert: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG 'output.png' @ warning/png.c/MagickPNGWarningHandler/1750.` – user Mar 25 '23 at 13:13
  • That sounds like your input is greyscale. – Tetsujin Mar 25 '23 at 13:17
  • @Tetsujin That is not the case. I used the same input image that I included as example in my post above. – user Mar 25 '23 at 13:28
  • Does [this post](https://superuser.com/questions/693339/batch-processing-images-of-documents-to-look-like-a-fax) help? – harrymc Mar 25 '23 at 16:51
  • @harrymc I have already viewed the post that you linked, as I have mentioned in my question. The problem is that method only works for B/W documents, not for colored documents. – user Mar 26 '23 at 11:53
  • use the android app you already know: https://uk.pcmag.com/blackberry-apps/121789/4-free-ways-to-run-android-apps-on-your-pc – 1NN Apr 06 '23 at 15:13
  • there are many online services, such as Cam scanner online : https://onlinecamscanner.com/ or this one: https://makescanned.com/ – 1NN Apr 06 '23 at 15:15
  • @1NN, using Android apps on Windows is cumbersome and also needs a computer with higher RAM than I currently have. So, I want something that can work natively. I also tried onlinecamscanner.com. Though the result looks fine visually, it has a huge filesize. For the same input image, ImageMagick produced an output with size of 62 Kb (though B/W) while the onlinecamscanner.com produced an output with size of 1744 Kb. – user Apr 07 '23 at 10:08
  • I don't think that only removing the colors would make the file 30 times smaller. The main reason I think is that the -threshold command in ImageMagick is removing color gradients in the background, which is making the PNG compression much more effective. So, I want something that can replicate this for colored images. – user Apr 07 '23 at 10:11
  • makescanned.com is not helpful because it doesn't do what is requested here. The purpose of that website is to make PDFs (such as those created using MS Word) to look as if they were produced by scanning paper documents. – user Apr 07 '23 at 10:14

0 Answers0