Converting from color to true black and white in ImageMagick?

10

5

I have seen how to convert a picture from color to grayscale in this Super User question and answer thread. However, grayscale is not black and white.

Simply put, if a field has color, I want to convert it to black. All other areas should be white. So, if a line 6 pixels thick is orange, the other thread's answer will turn the line gray. The line should be turned solid black.

However, is there a way to convert anything of any color at all (not white) to black?

I am working with Engineering prints, and it simply needs to be black or white. Gray does not work, because certain color lines become “gray” lines.

Sablefoste

Posted 2015-03-24T17:43:21.850

Reputation: 251

Question was closed 2015-03-26T15:37:44.190

2I am not sure I understand what your question is. – Ramhound – 2015-03-24T17:46:46.050

1Why does the answer in the linked question not work for you? – DavidPostill – 2015-03-24T17:49:14.483

@DavidPostill, please see my updated question. How to convert a solid orange line to a solid black line (not a solid gray line). I know gray is just black pixels mixed with white pixels, but this is not where I want it to go... – Sablefoste – 2015-03-24T21:54:56.207

Answers

11

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

DavidPostill

Posted 2015-03-24T17:43:21.850

Reputation: 118 938

2It does work! Now, I have to figure out how to remove the pixelation noise of the "close to white". Thank you for your response. – Sablefoste – 2015-03-25T12:51:46.330