Page 1 of 1

Set color & transparency based on condition

Posted: 2014-04-13T09:27:47-07:00
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

Re: Set color & transparency based on condition

Posted: 2014-04-13T10:46:00-07:00
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.

Re: Set color & transparency based on condition

Posted: 2014-04-14T12:09:06-07:00
by treeminator
Hi snibgo,

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