Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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)

share|improve this answer was far more helpful than the man pages – msw Jun 24 '10 at 16:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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