Search code examples
imagemagickmask

image magick: create black and white mask for color X


Starting with a 24bits image (png) I want to create a black and white image.

If input pixel is color X (say "#aabbcc") then output pixel should be black

Otherwise output pixel should be white.

I don't need any fancy things (tolerance and so on)

I tweaked the exemple at with http://www.imagemagick.org/discourse-server/viewtopic.php?t=13602

convert rmgcb.png \
\( -clone 0 \
-transparent '#aabbcc' \
-alpha extract \
-fill white -opaque white \
-transparent black \) \
-compose over -composite \
rmgcb_red_yellow_blue.png

But I stil need to convert original #aabbcc in black.

This will be part of a vectorization process: => histogram; sort color by surface; for each color (png=>ppm | potrace -o svg) | change color of svg | compile all svg


Solution

  • easier than what I thought

    convert input.png \
    -transparent '#aabbcc' \
    -alpha extract \
    output.ppm
    

    solution was gien at imagemagick forum

    http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=30834&p=139796#p139796