Page 1 of 1
Replicating Gimp "Color To Alpha"
Posted: 2014-12-20T14:16:35-07:00
by jbleach
Hi I was curious is anyone has any ideas on replicating how Gimp does "Color To Alpha" with IM. I can get close with a standard convert image.png -fuzz XX% -transparent white result.png, but Gimp is doing something additional with setting opacity or something on pixels that are left so it looks like you only have the color left with all of the white transparent. I have tried a couple things with setting white partially opaque but I can't seem to get the same affect as the Gimp "Color to Alpha".
Re: Replicating Gimp "Color To Alpha"
Posted: 2014-12-20T15:32:37-07:00
by dlemstra
Re: Replicating Gimp "Color To Alpha"
Posted: 2014-12-20T18:04:01-07:00
by fmw42
This has been discussed and solved on the forum before, but I cannot find the link. I wrote a unix bash shell script to emulate it. See my script color2alpha at the link below.
Re: Replicating Gimp "Color To Alpha"
Posted: 2014-12-22T09:31:57-07:00
by jbleach
Thanks for the replies, I searched and searched before posting and never found the stack overflow link you pointed me to. I will also try Fred's script again, when I tried before I couldn't get the affect I was seeing from Gimp. Since you are saying it is supposed to, I will try again and see what I was doing wrong. Thanks
Re: Replicating Gimp "Color To Alpha"
Posted: 2014-12-22T10:37:35-07:00
by fmw42
I used the GIMP example on the referenced page to develop the script. If it fails for one of your images, send me the image and I will take a look. You can post the image to dropbox.com and put the URL here.
Re: Replicating Gimp "Color To Alpha"
Posted: 2014-12-22T13:34:20-07:00
by jbleach
Ok, so the information from your replies gets most of the way there, but Gimp seems to be doing something additional to the remaining colors. I found that doing the following additional conversions gets me closer to what Gimp is doing for my needs. Posting in case it helps someone else.
//adjust colors
convert colortoalpharesult.png -colorspace sRGB -modulate 50,200,100 tmp.png
//make remaining colors semi-transparent
convert tmp.png -alpha set -channel A -evaluate Divide 1.2 tmp2.png
Re: Replicating Gimp "Color To Alpha"
Posted: 2016-01-22T02:23:21-07:00
by bomastudio
From the Gimp help
The Color to Alpha command makes transparent all pixels of the active layer that have a selected color. An Alpha channel is created. It will attempt to preserve anti-aliasing information by using a partially intelligent routine that replaces weak color information with weak alpha information. In this way, areas that contain an element of the selected color will maintain a blended appearance with their surrounding pixels.
So with an image with a white background and some gray areas how to replicate this behavior?
Re: Replicating Gimp "Color To Alpha"
Posted: 2016-01-22T02:25:57-07:00
by fmw42
As I wrote above:
This has been discussed and solved on the forum before, but I cannot find the link. So, I wrote a unix bash shell script to emulate it. See my unix bash script color2alpha at the link below.
Re: Replicating Gimp "Color To Alpha"
Posted: 2016-01-25T11:59:34-07:00
by bomastudio
I wrote a unix bash shell script to emulate it
I need to replicate it using ImageMagick only..... looking in the Gimp/src I found this
https://git.gnome.org/browse/gimp/tree/ ... d59edcb95d
Any way to do it with ImageMagick?
Re: Replicating Gimp "Color To Alpha"
Posted: 2016-01-25T12:30:12-07:00
by fmw42
Just look at the two IM commands at the end of my script. The script is just a shell to pass arguments to the IM code. It is really only two lines of IM code with a conditional for what kind of output you want. Given any one output, the two commands could be combined into one command line.
If you do not like what my script (commands) produce, feel free to write the IM code from the GIMP code and contribute it to the IM community.