Optimizing scanned documents with ImageMagick

I am in the process of scanning in all my paper receipts and correspondence. I use a small standalone document scanner that creates jpg images on an SD card. These documents are then converted into searchable PDF files.

The problem is that the images have not enough contrast to be easily readable on screen. Text is usually grey instead of black and you always see a grayish paper background.

Here comes ImageMagick to the rescue. You can easily stretch the color distribution so that light gray becomes white and dark gray becomes black. I use the following command line to modify all images in a folder before converting them to the PDF format:

for img in *.jpg; do mogrify -normalize -level 10%,90% -sharpen 0x1 $img; done

The level values fit my requirements. You should try different values if you don’t like the result.

Please note that pictures will look worse after the above step. Text documents will improve but the colors might change a bit.

Leave a Reply