The Computer Oracle

Converting from color to true black and white in ImageMagick?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop

--

Chapters
00:00 Converting From Color To True Black And White In Imagemagick?
00:48 Accepted Answer Score 15
01:48 Thank you

--

Full question
https://superuser.com/questions/893476/c...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#conversion #imagemagick

#avk47



ACCEPTED ANSWER

Score 15


How do I convert from color to true black and white?

If a field has color, I want to convert it to black.

Use the following command:

convert <input> -negate -threshold 0 -negate <output>

Threshold Dithering Methods

Threshold Images

The simplest method of converting an image into black and white bitmap (to color) image is to use -threshold. This is actually a simple mathematical operator that just provides a cut-off value. Anything equal to or below that value becomes black, while anything larger becomes white.

...

If you actually want to convert all non-pure white colors to black, then I recommend that you threshold the negated image instead of trying to work out the right threshold value to use (one less than IM's current 'MaxRGB'), a value that is dependant on your specific IM's compile time in Quality, or 'Q' setting.

convert logo.png -negate -threshold 0 -negate threshold_white.gif

Source Threshold Dithering Methods