LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-02-2018, 07:06 AM   #1
grumpyskeptic
Member
 
Registered: Apr 2016
Posts: 330

Rep: Reputation: Disabled
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.
 
Old 12-02-2018, 11:38 AM   #2
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,488

Rep: Reputation: 242Reputation: 242Reputation: 242
-black-point-compensation ? I've gotten useful answers on the fora @imagemagick.org
 
Old 12-03-2018, 03:23 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 15,798
Blog Entries: 9

Rep: Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626
Quote:
Originally Posted by grumpyskeptic View Post
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.
 
Old 12-09-2018, 04:52 AM   #4
grumpyskeptic
Member
 
Registered: Apr 2016
Posts: 330

Original Poster
Rep: Reputation: Disabled
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.
 
Old 12-09-2018, 07:05 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 15,798
Blog Entries: 9

Rep: Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626Reputation: 4626
Quote:
Originally Posted by grumpyskeptic View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Libre Office Writer document window colour grey instead of white dwhb Linux - Software 2 05-17-2017 12:04 PM
[SOLVED] Libre Office Writer document window colour grey instead of white dwhb Linux - Software 2 05-17-2017 09:29 AM
convert PDF files into monochrome single colour other than black and white fabriberloco Linux - Software 2 02-01-2013 09:56 AM
Batch Greyscale Image Converter to Full Color 24 bit JPEG? btbx Linux - Software 2 04-15-2008 06:32 AM
HELP! BASH - Convert filenames from dsc00***.jpg to *.jpg jimmybond01 Programming 9 05-08-2007 07:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration