Home > FAQ > Additional "How To" Suggestions > Putting the Alpha Channel to Work

Putting the Alpha Channel to Work

 

With the rush to achieve "photorealism" in computer graphics (defined as 16.7 million colors or "true color" ), context is quite often overlooked. Yet in order to get the graphics to accurately reflect what occurs in the real world, achieving "life-like" photorealism in computer graphics requires more than the display of color. Perhaps the most important aspect is the context into which the image elements are being displayed.

 

This is true whether rendering 3D models or compositing in 2D, the effective use of the alpha channel can save time, generate a polished look through automatic anti-aliasing, and offer simulation capabilities not possible through any other means.

 

What is the Alpha Channel?
In many paint and rendering software products, each pixel in an image is described by what are termed "channels" of data that define the mixture of the red, green and blue (RGB) colors making up the pixel. The newest generation of software adds another channel, called the alpha channel. Thus, these channels are referred to as RGBA (Red, Green, Blue, and Alpha).

 

This extra "alpha" channel defines the relative transparency of the pixel. It is an 8 bit (256 level) grayscale representation of the image and is used to "mask out" the color of the underlying pixel. Put another way, the value of the alpha mask regulates the intensity of the pixel color. In effect, if a mask is fully transparent, a red pixel would have full intensity (be fully visible bright red) and if the mask is completely opaque, this same red pixel will appear completely de-intensified (muted or "washed out").

 

You use alpha channels to create and store masks. Masks enable you to isolate and protect parts of an image while you apply color changes, filters, or other effects to the rest of the image. You can increase or decrease the intensity of this channel for every pixel in an image.

 

Context is King
The eye perceives the real world based entirely on context. This "edge definition" or contrast between two objects conveys how those elements are situated relative to each other. Without getting too philosophical, everything that we perceive is based on this "relativity". The alpha channel holds the essence of the information needed to establish relativity.

 

Every digital image is made from an array of pixels. Each of these pixels is diplayed at their full intensity, let's say 100. Let's also assume that you have a background image and you want to place an object, for example a tree, over this background. The tree contains a mask of varying intensities, allowing for varying amounts of the background to show through. The amount of the background coming through at any one point is the difference between the mask intensity at that pixel and 100.

 

Therefore, if the background is red, and the tree is green with a 50% mask, the final displayed pixel will be the admixture of 50% red and 50% green, or a muddy green. While this all seems very dry and technical, it is the key to how we perceive our real world in context. The reason this is so is because nothing exists in a vacuum. Everything that we see is influenced to some degree by what is behind it. Without the alpha channel information, nothing behind an object can come through, and we get the classical computer graphic look - "lollypops" for trees for example. Our senses immediately know it is a fake.

 

If we were to take a picture of a tree and scan it into the computer, cut it out and drop it onto a background image in a paint program without the alpha channel, it would sit there by itself "floating" on top of the background. Even if you use the blending tools to "smooth" the edges, it still will just be sitting there, floating above the background, completely out of context with the underlying image. Why? Because it wasn't seperated from it's original context!

 

Say for example the tree was against a blue sky background. When you scan it, it will have mostly blue-green pixels (an admixture of the the blue sky showing through the green leaves of the tree). Now place this tree "cut-out" over an orange brick walled building. Something look a little funny? Do you see the point here? A green tree against an orange background would yield an admixture of orange and green, not blue and green!

 

Alpha means Context
Well, not really, but it may very well have! Without the relative masking of the alpha channel involved in the rendering or compositing process, you end up with conventional computer graphics, not life-like photorealism. This concept is so little understood, that most computer software companies boasting photorealism fail to support the capability of the alpha channel, believing that color alone is sufficient to display photorealism.

 

How to Prepare an Object
It should now be readily apparent that if your goal is to convey a sense of realism in your renderings, you will need to both work with software that is alpha channel capable and prepare your objects (i. e. trees, people, etc.) to be rendered with the correct level of masking prior to the rendering or compositing process.

 

You can achieve the latter by either obtaining libraries where this work has already been done for you, allowing you to focus on task at hand, or preparing them yourself in the following manner. To do this, you will need an image processing program capable of creating grayscale mask on top of the image.

 

The first step is to prepare the mask to outline the object itself. This can be done in a variety of ways, and it varies depending on the capability of the software itself. If the software you are using supports a "quick mask" or "rubylith" technique, you may prefer to use paint tools to paint a mask over the object. With this step completed, you can then "lift" the object from the original background, placing it onto a solid 0,0,0 black or 255,255, 255 white background and saving this mask as the new alpha channel.

 

Next it will be necessary to modify the relative transparency of the alpha channel based on the background colors from the original image. This next step requires that you create color range selections, subtracting them from the new alpha channel just created.

 

Turning to our tree example, we do the following. Create a color range mask of the blues from the sky, with a tolarance setting such that the blue greens in the leaves are roughly at fifty percent opacity. The correct degree of this opacity depends on the real life condition of the object at hand, and you will need to judge accordingly here. If the leaves are thick and mostly opaque to the background, little if any of the mask should be covering them. If on the other hand the leaves are thin or airy, much of the color you're seeing is background color and the mask would well be greater than the fifty percent cited above.

 

Subtract this background mask from the above mask outlining the object, yielding an alpha channel that reflects the relative difference of the object to its background context. Save this new RGBA file and you're now ready to render or composite this object into any environmental context, creating a scene sure to convey life-like realism!

 

© 2009 Realworld Imagery Inc.