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?
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.