[SOLVED] Making translucency out of a given color range, in PNGs?

Discussion in 'Technical Discussion' started by ICEknight, Apr 27, 2011.

  1. ICEknight

    ICEknight

    Researcher Researcher
    Everybody knows that one of the cool features of PNGs is being able to make certain parts of them transparent or translucid, so you can see what's below them without resorting to ugly 256-color GIFs, but I was wondering if there's an automated process in existance for creating these transparencies from a specific color that's present in the image.

    I mean, something like the famous blue/green screens, where you can turn one of those colors transparent, leaving everything else untouched. Is it possible to do something like this with Photoshop or some other tool, without resorting to color indexing?


    All I've found is how to work with transparent layers (which I'm already familiar with, but isn't relevant to this case), or using the magic wand to just remove the selection (which is lame).

    Please, help? :(


    tldr EDIT:

    The goal is to turn this into this:

    <img src="http://img10.imageshack.us/img10/1249/example1dt.png" border="0" class="linked-image" /> -> <img src="http://img834.imageshack.us/img834/3124/example2j.png" border="0" class="linked-image" />

    Results so far:
    Photoshop Color Range selection:
    <img src="http://img853.imageshack.us/img853/9181/examplephotoshopcolorra.png" border="0" class="linked-image" />

    Paint.net:
    <img src="http://img51.imageshack.us/img51/6852/examplepaintnet.png" border="0" class="linked-image" />

    EDIT 2: We have a winner:
    GIMP's Color to Alpha tool:
    <img src="http://img854.imageshack.us/img854/5060/examplegimpcolortoalpha.png" border="0" class="linked-image" />
     
  2. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    Magic wand with global selection (so all pixels with that color are selected, regardless of where they are). Really there isn't much more to it... or are you trying to do batch processing on multiple files or something like that?
     
  3. ICEknight

    ICEknight

    Researcher Researcher
    <!--quoteo(post=582214:date=Apr 27 2011, 02:00 PM:name=Sik)--><div class='quotetop'>QUOTE (Sik @ Apr 27 2011, 02:00 PM) <a href="index.php?act=findpost&pid=582214"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Magic wand with global selection (so all pixels with that color are selected, regardless of where they are). Really there isn't much more to it... or are you trying to do batch processing on multiple files or something like that?<!--QuoteEnd--></div><!--QuoteEEnd-->
    That would be sweet, but I'm currently aiming at just doing it one by one.

    I don't think the magic wand is exactly what I'm looking for, as it will completely remove part of the image if it's green-tinted, instead of making it translucent. What I'd need is something similar to the hue/saturation tool in Photoshop, where you can select "Reds", "Greens", etc and change them altogether, only with the option of turning them into an alpha channel or something.
     
  4. Relick

    Relick

    Member
    197
    0
    16
    England
    C++/DX10 Engine (not sonic related)
    Have you tried Menu > Select > Colour Range?

    EDIT: Nevermind, I'm an idiot and can't read.
     
  5. ICEknight

    ICEknight

    Researcher Researcher
    <!--quoteo(post=582238:date=Apr 27 2011, 03:16 PM:name=Relick)--><div class='quotetop'>QUOTE (Relick @ Apr 27 2011, 03:16 PM) <a href="index.php?act=findpost&pid=582238"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Have you tried Menu > Select > Colour Range?<!--QuoteEnd--></div><!--QuoteEEnd-->
    Just tried that, and it's <I>almost </I>what I'm looking for, except that this also selects more stuff surrounding it than it should.

    As an example, if you select all the blues in your sig, then cut and paste them in the same place they were, the new blues will look too dim and there will still be some transparencies around. I'd just need a similar tool that would allow to make two images that can be merged into the original one.
     
  6. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    The magic wand only does selection of the color, it has nothing to do with what you do with it. You probably want to use the magic wand to select the region and then use some other tool to affect it. And yes, in a lot of programs you'll need to cut the selection into its own layer =/
     
  7. Relick

    Relick

    Member
    197
    0
    16
    England
    C++/DX10 Engine (not sonic related)
    <!--quoteo(post=582344:date=Apr 28 2011, 03:46 AM:name=Sik)--><div class='quotetop'>QUOTE (Sik @ Apr 28 2011, 03:46 AM) <a href="index.php?act=findpost&pid=582344"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->you'll need to cut the selection into its own layer =/<!--QuoteEnd--></div><!--QuoteEEnd-->
    This is pretty much what I was thinking. As said earlier, it's possible there is a batch tool to select a hex colour and change it to a chosen opacity. Otherwise you <I>will</I> need to put it in a new layer :(. Colour Range is a tricky tool, set the fuzziness (tolerance) too high and you are getting colours you don't want. Set it too low and you aren't getting all of the selected colour. What I tend to do is select all I want, then slide fuzziness up and down until I get a suitable selection.
     
  8. ICEknight

    ICEknight

    Researcher Researcher
    <!--quoteo(post=582416:date=Apr 28 2011, 02:33 AM:name=Relick)--><div class='quotetop'>QUOTE (Relick @ Apr 28 2011, 02:33 AM) <a href="index.php?act=findpost&pid=582416"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec--><!--quoteo(post=582344:date=Apr 28 2011, 03:46 AM:name=Sik)--><div class='quotetop'>QUOTE (Sik @ Apr 28 2011, 03:46 AM) <a href="index.php?act=findpost&pid=582344"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->you'll need to cut the selection into its own layer =/<!--QuoteEnd--></div><!--QuoteEEnd-->
    This is pretty much what I was thinking. As said earlier, it's possible there is a batch tool to select a hex colour and change it to a chosen opacity. Otherwise you <I>will</I> need to put it in a new layer :(. Colour Range is a tricky tool, set the fuzziness (tolerance) too high and you are getting colours you don't want. Set it too low and you aren't getting all of the selected colour. What I tend to do is select all I want, then slide fuzziness up and down until I get a suitable selection.
    <!--QuoteEnd--></div><!--QuoteEEnd-->
    Yeah, it stinks that no matter what you do, the results of cutting a color range selection and then pasting it in place are always different than the original picture. Then, doing the same with the magic wand does give the original pic as a result, but there's no translucency in those selections, just 100% or 0% opacities.

    I've also tried selecting a whole channel (R,G,B), but that presents the same issues of a normal color range selection. If only it was possible to directly turn a color range into alpha...


    That color range selection tool would be perfect to use, <I>if </I>it worked properly. That's a real shame. =\



    EDIT: Just found about a <a href="http://www.greenscreenwizard.com/GSWHelp/UsingPhotoshopPlug.htm" target="_blank">green screen plugin for Photoshop</a>... but it's $150. =P
     
  9. Polygon Jim

    Polygon Jim

    Eternal Tech Member
    0
    0
    0
    across town from Hinchy
    All the bitches.
    The colour range selection tools does this perfectly, I always use it if I want to make a sprite sheet have transparency.

    1.) Copy the image into a new layer as the BG can't be transparent in Photoshop.
    2.) Use the colour range tool to select the transparency colour, and set the Fuzziness value to 0%
    3.) Hit "Delete" on your keyboard.
    4.) ????
    5.) Profit.

    This method will work perfectly as long as there's nothing in the image that use the exact same RGB values as the background you are trying to delete.

    Here's a random sheet I had around that I just gave a transparent background this way, the original being <a href="http://www.spriters-resource.com/genesis/soniccrack/sheet/5909" target="_blank">here</a>.
    <img src="http://I.imgur.com/1O6k4.png" border="0" class="linked-image" />
     
  10. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    You know, I think he actually means he wants to take a grayscale image and turn it into an alpha map...
     
  11. Black Squirrel

    Black Squirrel

    waiting for you on the beach Wiki Sysop
    5,248
    77
    28
    Northumberland, England
    it's a quipu
    Alternative - <a href="http://www.getpaint.net/" target="_blank">Get Paint.NET for free</a>, select magic wand, change the flood mode to global, make sure colour tolerance is at 0%, press delete. Success.

    Photoshop is a wonderful tool if you're making really high quality professional work, but I find that Paint.NET is a far less bloated, easier to use, powerful alternative that gets the job done if you're only doing things like spritework or "internet" images (and there's tons of plugins... including a PSD one).

    And it's exceptionally good with transparency. I don't know if Photoshop does this, but it'll retain the transparency of copied/pasted images. Incredibly useful. I can't really think of much it <I>can't</I> do.
     
  12. ICEknight

    ICEknight

    Researcher Researcher
    <!--quoteo(post=582454:date=Apr 28 2011, 09:10 AM:name=Polygon Jim)--><div class='quotetop'>QUOTE (Polygon Jim @ Apr 28 2011, 09:10 AM) <a href="index.php?act=findpost&pid=582454"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->The colour range selection tools does this perfectly, I always use it if I want to make a sprite sheet have transparency.

    1.) Copy the image into a new layer as the BG can't be transparent in Photoshop.
    2.) Use the colour range tool to select the transparency colour, and set the Fuzziness value to 0%
    3.) Hit "Delete" on your keyboard.
    4.) ????
    5.) Profit.

    This method will work perfectly as long as there's nothing in the image that use the exact same RGB values as the background you are trying to delete.<!--QuoteEnd--></div><!--QuoteEEnd-->
    ...That doesn't have any translucencies, it's something that could be easily done with an indexed palette. I know selecting a single color is easy, but I want to select the range of all greens, or blues, etc.

    More graphically, I want to turn something like this:
    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec--><img src="http://img10.imageshack.us/img10/1249/example1dt.png" border="0" class="linked-image" /><!--QuoteEnd--></div><!--QuoteEEnd-->
    Into something like this:
    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec--><img src="http://img834.imageshack.us/img834/3124/example2j.png" border="0" class="linked-image" /><!--QuoteEnd--></div><!--QuoteEEnd-->


    I'll try paint.net and see what I get.


    EDIT:

    Results with Photoshop's Color Range selection:
    <img src="http://img853.imageshack.us/img853/9181/examplephotoshopcolorra.png" border="0" class="linked-image" />

    Results with Paint.NET:
    <img src="http://img51.imageshack.us/img51/6852/examplepaintnet.png" border="0" class="linked-image" />


    <=(
     
  13. Polygon Jim

    Polygon Jim

    Eternal Tech Member
    0
    0
    0
    across town from Hinchy
    All the bitches.
    The way you described it in the first post seemed like you just wanted to make a single colour transparent for the background.

    As far as I'm aware, what you are trying to do can't be done with just a single tool. You'll need to remove the main background colour, then move the parts of the image you want to have lower opacity to a new layer and set it's opacity to whatever you want, and you'll probably also need to mess with the hue of that layer a bit as well to make it look correct.

    Edit:

    This method should turn out correctly for you, I tried it with your example image.

    My version from the image with a green background.
    <img src="http://I.imgur.com/Qluf5.png" border="0" class="linked-image" />

    You can get better results if you try harder, I did this really fast so it's not perfectly accurate to what the transparent example looks like.
     
  14. Clutch

    Clutch

    It was a dark and stormy night... Member
    1,653
    0
    16
    GIMP has a "Color to Alpha" option (which does what you'd expect), but because of common base colors you might end up with areas that become slightly transparent when you didn't want them too.

    I tend to magic want select the areas I want to get rid of, slightly increase how far the selection extends and <I>then</I> use that tool. Doesn't always work the best, but it's how I managed stuff like my Donkey Kong images.
     
  15. ICEknight

    ICEknight

    Researcher Researcher
    <!--quoteo(post=582621:date=Apr 28 2011, 05:28 PM:name=Clutch)--><div class='quotetop'>QUOTE (Clutch @ Apr 28 2011, 05:28 PM) <a href="index.php?act=findpost&pid=582621"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->GIMP has a "Color to Alpha" option (which does what you'd expect), but because of common base colors you might end up with areas that become slightly transparent when you didn't want them too.

    I tend to magic want select the areas I want to get rid of, slightly increase how far the selection extends and <I>then</I> use that tool. Doesn't always work the best, but it's how I managed stuff like my Donkey Kong images.<!--QuoteEnd--></div><!--QuoteEEnd-->
    Oh my fucking god.

    This is the original.
    <img src="http://img10.imageshack.us/img10/1249/example1dt.png" border="0" class="linked-image" />

    This is my goal.
    <img src="http://img834.imageshack.us/img834/3124/example2j.png" border="0" class="linked-image" />

    This is what I get when using the Color to Alpha tool in GIMP:
    <img src="http://img854.imageshack.us/img854/5060/examplegimpcolortoalpha.png" border="0" class="linked-image" />

    I fucking love you. That's exactly what I was looking for, thank you so much.


    I would have never expected to find such a thing in GIMP. So it turns out that this free (but quite messy) alternative to Photoshop also has some exclusive tools. Go figure.


    Thanks for the help, guys. I hope this has been useful to other people as well.
     
  16. Clutch

    Clutch

    It was a dark and stormy night... Member
    1,653
    0
    16
    Glad to be of help, I've gotten a lot of mileage out of GIMP.