Jonathan Snakes
Jonathan Snakes

Reputation: 1

How to make a three-coloured-image with ImageMagick on the command line?

I need to convert jpgs to three-coloured-pngs with ``convert'' that allow black, white and gray (#808080).

Every color that's near black (#000000) should be converted to black, every color that's the nearest to gray should be converted to that and every color that's near white should be converted to that color.

Posterizing only does half of the job since, posterized, the gray-value might change. I need it to be exactly #808080.

Is there any way to do that?

Upvotes: 0

Views: 239

Answers (1)

GeeMack
GeeMack

Reputation: 5395

You can do that by creating a map with only the three colors you want, then remap the image to use just those colors. A command to do that would look something like this...

convert input.png +dither \
   \( xc:black xc:gray50 xc:white +append -write mpr:map +delete \) \
   -remap mpr:map -set colorspace RGB output.png

If you're using Windows you should change those continued line backslashes "\" to a caret "^". Also, you won't need to escape the parentheses with backslashes.

Edited to add: I added "-set colorspace RGB" before the output to make sure the result is linear which should assure the output is faithful to the colors you specify in the map.

Upvotes: 1

Related Questions