# BW to Alpha

Hi,

How can I use nodes to convert a black and white image to an alpha map with the black parts equalling zero alpha and the white parts equalling alpha 1?

Related: Is there anything like a “Combine RGBA” node, where I can do the opposite of separate? Take 4 RGBA curves and plug them in? For example, if I wanted to take all the red values of one node and swap them with blue values, how would I do that?

T

You connect the image output socket from your B&W image or movie to an alpha input socket such as the one located on a composite node. This is definitely the most painless way to do it but you really won’t learn anything that way so I sugest experimenting as there are really lots of ways to do it. You might try it with a mix node via channel operations such as subtract and multiply. Just keep playing with them, they’re rather new to me too. Also, if you need an inverted alpha matte, just connect your source image or alpha to a color ramp node and reverse the positions of the black and white sliders. Nodes are the most aggravating fun I’ve ever had.

Well, I only need one way to do it, and I’m already experimenting. An alpha input socket is part of what I’m looking for, but there aren’t alpha sockets on any nodes other than the composite node, as you mentioned (which is no good because that’s just an output node) and the “set alpha” node, which I’m still fiddling with, but doesn’t seem to be quite what I want, at least on its own.

Basically, what I want to do is to convert a color value to an alpha value, and then to use that alpha value to mix (probably using something analogous to “lighten” with the alpha value of another render layer. I don’t know yet whether “lighten” itself operates on alphas or only on colors)…

Are you talking shading nodes or compositing? There is Combine RGBA in comp nodes in CVS, but not shading atm.

There is Combine RGBA in comp nodes in CVS

Aha! Cool. I had a feeling that I’d stumbled on a glaring omission. I’ll have to try my plan out with a CVS build.

fun times. just wrote the wiki today. With the separate rgba node; each output channel is a BW image showing the intensity of that electron gun. The alpha is a BW image as well. So you could feed a channel in as an alpha, and thus have all the blue things in a picture become invisible, with green things partially visible (since they are blue and yellow). You could even have like two completely different images alpha each other out.

To do what I think you want and use a mask, create a black pic with a white circle. Like you said, black is zero is alpha zero is transparent. I created a white sphere in front of a black shadeless plane; that way I can move the sphere around. Feed that into the TOP socket of a color mix node with the Multiply function. Set the Factor to 1. Feed your picture into the Bottom socket. So, Top image pixel black=0 times bottom color Red times factor 1 = 0 and it comes out black. Where a top mask pixel is white=1, times the bottom pixel (say Green) times factor 1 puts out Green. Blurring the circle edge of course creates a softness at the edge.

With factor=1, top and bottom location is irrelevant. However, the default factor of .5 tries to mix the image with the mask if they are reversed. curious.

btw, one would think that plugging in a BW image into an alpha channel of a composite output node would use the image as the alpha channel, but alas, it uses the alpha channel of the bw image, which is usually all white. even when i save the image to a non-alpha channel format (JPG), and use the file image input node, it still does not want to use the image as the alpha. bug??? or, maybe black is not zero like it is in textures…

never mind the bug question - an image is a yellow socket and alpha a gray. Connecting results in socket data type mismatch (ignore). We need a Convert Image to Alpha node. Having said that, a RenderLayer input with a scene that has only a ball in it should produce an image AND alpha layer of a ball. You can then run it’s alpha to your picture. The opposite mask you would run it thru the xy translator with the line going down left-to-right to inverse the output.

let me know if any of this works or if I am off base, ok?

I’m not sure what you’re getting at in these posts, they’re quite confusing. But I can at least clarify that in the compositor, it’s perfectly safe to connect up different socket types (eg. an RGB image output going into a BW input). Blender dynamically converts between types and it all works fine. Give it a try!

We need a Convert Image to Alpha node.

There is already a Set Alpha node, that you can plug an image in to.

Plugging any image output into the input socket of a color ramp will allow you to use the luminance data of that image’s RGB channels (rather than it’s alpha channel) as an alpha matte for any other image, you can also reverse the B&W sliders on the ramp to invert the matte.