Painting into the Alpha Channel

The alpha channel of RGBa images controls the transparency of each pixel in the image. Each pixel in an RGBa image has a value from 0 to 255 in the alpha channel that specifies how transparent that pixel should be. A value of 0 means no transparency and a value of 255 means total transparency.

 

Just like we can turn on and off the R, G and B channels of an image we can also turn the alpha channel on and off. If all the channels of an RGBa image except the alpha channel are turned off, the alpha channel will appear in shades of gray from black to white that show the transparency that will apply in different parts of the image. Because Manifold painting tools apply only to those channels that are enabled, we can enable only the alpha channel and then paint into it using different shades of gray to "paint" different levels of transparency into different parts of the image.

 

This example explores use of the Paint Bucket and Gradient painting tools used with different colors and different opacity settings to create different transparency effects.

 

images\eg_alpha_00.gif

 

We will use our standard bronze image as an example. The window on the left shows the bronze image in an image window. We have selected all pixels outside the bronze monument and have deleted them. We then used Edit - Select Inverse to invert the selection and thus select only the pixels inside the monument. See the Selection topic for examples of selection techniques.

 

The window on the right shows a map window open to a map that has two layers: the bronze image on top and underneath our sample schloss image of the Neuschwanstein castle. The schloss image has been colorized to provide a softer visual background for the bronze image on top. We have used the Image - Convert To command to convert the RGB bronze image into an RGBa image.

 

images\eg_alpha_d01.gif images\eg_alpha_01.gif

Throughout this example we will use the Border selection style. The region of selected pixels is outlined in red. We will be working in the image window, as shown on the left. The map window as seen on the right will show the effect of each operation. Each window in Manifold has its own channel settings so we can configure the image window on the left to show only the alpha channel while the map window on the right shows the R, G, B and alpha channels. Channels may be turned on and off in the Layers pane.

 

images\eg_alpha_d02.gif images\eg_alpha_02.gif

We begin by turning the R, G and B channels off in the image window. This leaves only the alpha channel on. The image appears in black since all pixels have a zero alpha value, that is, zero transparency.

 

Using the Paint Bucket

 

We will now set up our tool controls to use the paint bucket tool.

 

images\btn_paint_bucket.gif In the Tools toolbar for images we choose the Paint Bucket tool.

 

images\eg_alpha_t03.gif In the Tool Properties pane we choose Opacity of 10.

 

images\eg_alpha_f03.gif

In the Format toolbar we change the foreground color to white.

 

Let's consider what the above settings will accomplish. Whatever we pour the paint bucket into, we will be pouring white color with opacity of 10. That means that the white color will pour into pixels with only about 10% of the effect of pure white. If the white color is poured into a region of black pixels, they will lighten by about 10% with each pour of the paint bucket. After ten pours the color should be nearly white. Note that the paint bucket will pour paint only into the region of the image that is selected. All parts of the image outside the selection will be unaffected by the paint bucket.

 

images\eg_alpha_d03.gif images\eg_alpha_03.gif

If we now pour the paint bucket into the black pixels in the image window a few times we see they will lighten into gray color. With each pour of the paint bucket we lighten the gray shade that we see in the alpha channel in the image window. Simultaneously the full RGBa image we see in the map window will become more transparent and more of the schloss image will show through. A lighter shade of gray in the alpha channel indicates a higher alpha value for each pixel, or more transparency.

 

images\eg_alpha_f04.gif

We can switch the foreground color in the Format toolbar to black. If we now pour the paint bucket (leaving the opacity at 10) it will darken the region of pixels with each pour.

 

images\eg_alpha_d04.gif images\eg_alpha_04.gif

Darkening the shade of gray by pouring darkness into the alpha channel will reduce the transparency of the image. Darker shades in the alpha channel mean less transparency. Less of the schloss image will show through.

 

Note that we could always have chosen some shade of gray for the foreground color and poured that shade of gray directly into the selected region in the image with opacity set to the default value of 100. Pouring pure black or pure white color with opacity of 10 is an indirect method. It has the advantage of allowing us to pour several times and to adjust the transparency interactively. This indirect, interactive method can be easier than choosing various shades of gray in the color picking dialog until we get the one that provides the transparency we want.

 

Also note that the alpha transparency takes on the intensity of the color painted into it. We could have selected colors other than black or white (or shades of gray) for the foreground color in the format toolbar and then painted with those colors. If a different color, such as light blue, were poured into the alpha channel it would appear in the alpha channel as the shade of gray that represents the intensity of that light blue color. Because it is difficult for most people to accurately estimate the intensities of colors other than shades of gray it is best to use shades of gray when painting into the alpha channel.

 

Using the Gradient Tool

 

images\btn_gradient.gif In the Tools toolbar for images we choose the Gradient tool.

 

images\eg_alpha_t05.gif In the Tool Properties pane we choose Opacity of 100. This will allow us to paint the gradients with full opacity. Painting with the gradient tool therefore will totally override the previous colors of the pixels.

 

images\eg_alpha_f04.gif

We will leave the foreground color black and the background color white. The gradient tool will create a gradient from black to white, beginning with black at the point we begin our click and drag and ending in white at the point where we end our click and drag. All parts of the image beyond the beginning will be solid black and all parts of the image beyond the end will be solid white.

 

Note that the gradient tool will paint only into the region of the image that is selected. All parts of the image outside the selection will be unaffected by the gradient tool.

 

images\eg_alpha_d05.gif images\eg_alpha_05.gif

In the image window we click where we want the gradient to start and then drag down to where we want the gradient to end and then release. The + cursor shows where we will release.

 

images\eg_alpha_d06.gif images\eg_alpha_06.gif

Everything before the beginning of the click and drag is painted black and then the gradient transitions from black to white at the point of release. This causes a range of smoothly increasing alpha values in the alpha channel (shown as the smooth transition in gray scale from black to white) that are seen in the map window as smoothly increasing transparency. In the map window we can see that the head and shoulders of the monument are not at all transparent while the lower right regions of the monument are completely transparent. We will leave the selection color enabled in the map window so we can see where the bronze image would be if it were not transparent.

 

images\eg_alpha_d06a.gif images\eg_alpha_06a.gif

We can click and drag again with the gradient tool to create a transition from black to white over a shorter distance.

 

images\eg_alpha_d07.gif images\eg_alpha_07.gif

The result of the shorter click and drag is a gradient that rapidly changes from black to white. Note that much more of the image in the map window is now fully transparent.

 

Note also that the pixels have not been deleted (as they might be in the case of invisible pixels ) but have simply had their alpha transparency turned up to high transparency values. At any time we can paint different colors into the alpha channel to change the transparency of any of the visible pixels. For example, we could paint a darker color into the alpha channel to lower the transparency and make the pixels less transparent. Or, as seen in the steps above, we could use the gradient tool to paint different gradients into the selected region.

 

images\eg_alpha_d07a.gif images\eg_alpha_07a.gif

We can use the gradient tool in any direction. In the above screen shot we have clicked at the upper right and dragged down to the lower left.

 

images\eg_alpha_d08.gif images\eg_alpha_08.gif

This results in a gradient being painted into the alpha channel that is dark in the upper right and lighter in the lower left.

 

Although the above examples have shown the gradient tool being clicked and dragged mostly within the selected area, if desired we can click and drag it in any part of the image. Because the effect of the gradient tool will be seen only within the selected area, we have been clicking and dragging mostly within the selected area in these examples. That makes it possible for the effect of the gradient tool to be easily seen as it is applied to the visible pixels in the monument.

 

Edges

 

We can use almost any effect or tool we desire on the alpha channel. If we want to restore the alpha channel to no transparency (all black), the easiest way is to simply use the Brightness / Contrast command in the Image menu to turn the Brightness all the way down to zero.

 

images\eg_alpha_d09.gif images\eg_alpha_09.gif

This has the effect of making all the pixels in the selected region's alpha channel black. This restores the image to zero transparency for all visible pixels.

 

images\btn_selstylarrow.gif We can click on the Selection Style button to toggle use of red selection color on and off to show the region of selected pixels. If we temporarily turn off selection color, we can see how the image looks. Note that from the map window screen shot on the right we can see that we did a sloppy job of selecting the pixels of the monument, as can be seen by the halo of white edge pixels in the lower part of the monument.

 

Even if we are careful when selecting pixels within images it is often difficult to avoid some "halo" effect in parts of the image where transitions from dark pixels to light pixels occur. Such transitional regions often contain anti-aliased pixels that help provide a smoother appearance in the context of the entire image but which stand out as unnaturally light when only part of the image is visible.

 

images\eg_alpha_d10.gif images\eg_alpha_10.gif

We will deal with this in a subtle way. First, we turn selection color back on. We then use the Edit - Modify Selection command to create a Border selection using a border that is 2 pixels wide on either side of the previous edge. This takes the edge of existing selection and creates a narrow selection that follows the edge in the given width.

 

In the screen shots above, if we look closely into the map window we can see that the selection is a ribbon of border that is a few pixels wide that follows the edges of the previous selection. This new selection covers all of the white pixels that were making an ugly halo at the bottom of the monument.

 

images\eg_alpha_b10.gif images\eg_alpha_b10a.gif

If we were to zoom into the image and use the dense dots selection style to show selected regions, the illustration on the left shows a close-up view of the edge of the selected region in the monument. The view on the right shows the same view after application of the Edit - Modify Selection - Border command with a value of 2 for the border. Normally, the border created would extend two pixels to either side of the previous edge for a total border width of five pixels. Because the edge of the previous selection in this case is bordered by invisible pixels the border ends up being only three pixels wide.

 

images\eg_alpha_d11.gif images\eg_alpha_11.gif

We now use Brightness / Contrast once more to make all the pixels in the selection white by increasing the Brightness. Making all the pixels in the selection white makes them completely transparent. This gets rid of the halo pixels as can be seen in the map window when we turn off selection color temporarily; however, it also gives the appearance of "cropping" the pixels in the upper part of the bronze monument where there was no halo problem.

 

images\eg_alpha_d11a.gif images\eg_alpha_11a.gif

The solution to this problem is to use the gradient tool once more. We click in the middle of the image and drag down and release at the bottom. Even though we have temporarily turned off selection color the selection is still there. The gradient tool will work only on that three-pixel wide ribbon of selected pixels that follows the border of the image. The effect of the gradient will cause the upper part of the selected border to be black for zero transparency and the bottom part of the selected border to be white for total transparency.

 

images\eg_alpha_d12.gif images\eg_alpha_12.gif

This creates the effect we want. Note that the image in the map does not show any clipping of pixels about the head of the monument while at the feet there is total transparency so that the halo white pixels do not show because they are completely transparent. If we look very closely at the image window screen shot on the left we can see the gradient in color from black to gray to white in the thin ribbon of pixels at the border of the image.

 

images\eg_alpha_d13.gif images\eg_alpha_13.gif

To see the gradient effect in the border, we can use Edit - Select Inverse once more to select all pixels except those previously selected in the border region. This selects all pixels outside the thin border selection. We can then use Brightness / Contrast to increase the brightness of all these pixels to full white. This will make all pixels completely transparent except those pixels that were in the border selection. This allows us to see the gradient from black to white in the image window at left and the resulting effect at in the map window at right.

 

There are, of course, different ways of dealing with "halo" pixels than the above. We used the gradient and transparency because in this particular image the halo problem existed only in one region of the image.

 

See Also

 

Images and Channels