LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Convert a batch of colour jpg document scans to black and white rather than greyscale (https://www.linuxquestions.org/questions/linux-software-2/convert-a-batch-of-colour-jpg-document-scans-to-black-and-white-rather-than-greyscale-4175643501/)

grumpyskeptic 12-02-2018 06:06 AM

Convert a batch of colour jpg document scans to black and white rather than greyscale
 
I have a large number of colour .jpg scans of old yellowing document pages that I want to batch convert to black and white - i.e. each pixel should be either black or white, not grey.

I used the following command-line script, found in another forum, but it only gives blackish text on a pale grey background:

for img in $(find . -iname '*.jpg'); do echo -n "Converting $img"; convert -colorspace GRAY $img $img && echo ' [Done]'; done

I also tried replacing the "-colorspace GRAY" part with "-monochrome" but this gives speckled pages with unreadable fuzzy text.

What should I do to get black text and diagrams on a white background?

Thanks.

RandomTroll 12-02-2018 10:38 AM

-black-point-compensation ? I've gotten useful answers on the fora @imagemagick.org

ondoho 12-03-2018 02:23 AM

Quote:

Originally Posted by grumpyskeptic (Post 5932454)
I want to batch convert to black and white - i.e. each pixel should be either black or white

no, that's not what you want (as you already noticed).
you want the letters to be black, and the background to be white.
you're simply going to have to fiddle with imagemagick until you find an individual setting that works for you.

btw, a technically black/white image (i.e. only 2 colors) usually looks horrible, you probably still want grayscale, but with more contrast.

grumpyskeptic 12-09-2018 03:52 AM

Thank you Ondoho and RandomTroll. I had not realised that the script was using ImageMagic.

This script, using "convert -threshold 30%" did the job.

for img in $(find . -iname '*.jpg'); do echo -n "Converting $img"; convert -threshold 30% $img $img && echo ' [Done]'; done

Warning: all the above scripts replace the image files rather than making a copy.

Thanks.

ondoho 12-09-2018 06:05 AM

Quote:

Originally Posted by grumpyskeptic (Post 5935014)
Warning: all the above scripts replace the image files rather than making a copy.

i didn't even know that "convert $img $img" was possible, but you can also use mogrify for that, part of the same imagemagick package: "mogrify $img"

you're welcome.


All times are GMT -5. The time now is 10:51 AM.