I would check that a a color like #FFFFFFFFFFFe does go to black before trusting that command for colors. (I lowercased the 'e' to make it more obvious)
Code: Select all
convert xc:'#FFFFFFFFFFFe' -threshold 100% txt:
But then so does white!
Code: Select all
convert xc:'#FFFFFFFFFFFF' -threshold 100% txt:
The negated method however works find for a gray scale value...
Code: Select all
convert xc:'#FFFeFFFeFFFe' -negate -threshold 0 -negate txt:
(producing black as wanted)
But the one bit color change produced white which is NOT wanted.
Code: Select all
convert xc:'#FFFFFFFFFFFe' -negate -threshold 0 -negate txt:
Remember threshold is really a grayscale channel operator with a 'fudge' for handling color images. To get get a perfect, not-white, method you can do one of two things..
1/ threshold each channel image separately and then recombine appropraiteally so result is white only if all three channels are white.
Code: Select all
convert xc:'#FFFFFFFFFFFe' \
-channel RGB -separate +channel \
-negate -threshold 0 -negate \
-background white -compose multiply -flatten txt:
Try it also with pure white.
This is tricky, and can fail for some specific versions of IM, where the threshold level was not quite 'normal'. Note that the current documentation for threshold is actually wrong!
2/ A simpler solution for images without transparency, is to use the color replacement functions to 'make a hole' for the exact color selected, then invert the transparency, and underlay a black background.
Code: Select all
convert image.png -matte -transparent white \
-channel A -negate +channel \
-background black -flatten \
result.png
this will work for any EXACT color, replacing anything not that color with any other color you like, not just white and black. You can also use a -fuzz factor to broaden the range of colors.
PS: I would like to see +transparent and +opaque changed to mean a 'not this color' so as to remove the need for the transparency channel to invert the result.