Set color & transparency based on condition

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
treeminator
Posts: 2
Joined: 2014-04-13T09:22:59-07:00
Authentication code: 6789

Set color & transparency based on condition

Post by treeminator »

Hi,

how can I use the convert tool to set the color of a pixel to a specific color if it fullfills certain conditions regarding it's RGB color values (e.g. R-value > 100 && G-value >80 && B-value >150) and set it to transparent if the condition is hurt?

Thanks a lot
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Set color & transparency based on condition

Post by snibgo »

I don't understand exactly what you want, but "-fx" can probably help. See http://www.imagemagick.org/script/fx.php

For example:

Code: Select all

convert in.png -fx "r>0.3922&&g>0.3137&&b>0.5882?white:u" out.png
Note that 100/255 = 0.3922 etc. Where the condition is true, that pixel becomes white. Otherwise it is unchanged.
snibgo's IM pages: im.snibgo.com
treeminator
Posts: 2
Joined: 2014-04-13T09:22:59-07:00
Authentication code: 6789

Re: Set color & transparency based on condition

Post by treeminator »

Hi snibgo,

great! Exactly what I was looking for. Works pretty well!
Post Reply