Let's say I have an image that is basically two colors, red and white. However there are also parts of the image that are a little bit off white. I want to change those parts to be white, so that the image only has two colors. What program can do that from the command line?

link|improve this question

65% accept rate
feedback

1 Answer

up vote 4 down vote accepted

convert -posterize 2

hmm, that didn't work as expected

convert -colors 2 +dither gradient.png bicolor.png

meh, there is an intensity mapping that forces white into grey thus

# create a 2 color image from scratch to supply colors for mapping
$ convert -size 10x10 xc:white -fill red -draw 'rectangle 0 0 5 5' \
    -colors 2 +dither bicolor.gif
# map 'em, Danno!
$ convert -colors 2 -normalize +dither -remap bicolor.gif in.png out.png

worked. Note: a prior version of this answer used mogrify instead of convert, I changed it because mogrify overwrites the original in-place while convert doesn't but they use the same algorithms and arguments.


bicolor.gif in.png out.png
(where the white doesn't stand out so well here)

link|improve this answer
imagemagick.org/Usage was far more helpful than the man pages – msw Jun 24 '10 at 16:50
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.