[magick-users] selecting all but a color?

David Vanderson dvanderson at customink.com
Thu Jun 14 08:02:37 PDT 2007


Anthony Thyssen wrote:
> David Vanderson on  wrote...
> | Hello,
> | 
> | Does anyone have a suggestion for how to select everything that's not a 
> | specific color?
> | 
> | For instance, in the following command I'm trying to make everything but 
> | magenta transparent:
> | convert -channel "RGBA" -colorspace "rgb" in.png +matte -transparent 
> | "magenta" -fill "black" -colorize "100%" -background "magenta" -flatten 
> | -transparent "black" out.png
> | 
> | This does work but seems overly complicated.  I'm hoping there's a more 
> | straightforward way.
> | 
> There is currently no negated  -opaque  operator.
> You also do not need the -channel or the -colorspace options in the
> above.
>
> So the above basically uses the selected color as a mask to invert the
> result.
>
> An alturnative is to use the NEW  change_mask  composite operator..
> Which I added to IM v6.3.4
>   http://www.imagemagick.org/Usage/compose/#changemask
>
>   convert  in.png  \( +clone +matte -fill magenta -colorize "100%" \) \
>            -compose ChangeMask -composite    out.png
>
> This compares each color in the in.png  with another 'all magenta' image
> that is the same size, and makes anything that is the same transparent.
>
> That is what is magenta is cleared.
>
> To invert, compare the image to itself, but with the magenta colors
> changed, to anything else!
>
>   convert in.png \( +clone -fill black -opaque magenta \)
>           -compose ChangeMask -composite    out.png
>
> The parts of the first (original) image that changed color (magenta
> areas) will be returned.
>
>
> You can check if your IM has this Alpha Composition method using...
>     convert -list composite | grep ChangeMask
>
> It was added to allow changes from one frame to the next to be detected
> and simplified for a new GIF Animation Compression Optimization,
> "-layers OptimizeTransparency" to make animation file sizes smaller.
>   http://www.imagemagick.org/Usage/anim_opt/#opt_trans
>
> It was also incorperated into the General GIF Optimizer operator...
> "-layers Optimize"
>   http://www.imagemagick.org/Usage/anim_opt/#optimize
>
>   
This is the best response I've ever gotten on any mailing list.  Thank 
you very much Anthony.
Dave


More information about the Magick-users mailing list