Tutorial 3.1: Using the Z Channel, Pixel Analyzer, and Color Correction

This tutorial discusses manipulation of the Z channel and also dips into a small discussion of premultiplication during color correction.

A Z channel is the distance of a pixel from the image plane (the camera). This information usually comes from a 3D render, and can precisely indicate a pixel's distance from the 3D camera. Pixels with higher Z values are further away from the camera than pixels with lower Z values.

The Composite

Most composite nodes depend on the RGB and alpha channels to calculate the final composite. Depth compositing uses a fifth channel, the Z channel, that orders pixels according to a certain depth from the pixel plane. Generally, Z channels are generated with a 3D renderer. Z channels are simple to generate, since every pixel has a certain distance from the camera. Z compositing takes the pixel with the lower Z value when it compares two images. Z channels can be rendered into the same file as the RGBA, or saved into a separate file and later loaded with a Copy node using z as your channel. In this tutorial, use both techniques to composite 3D-rendered blimps into a (really bad) scan of New York City. First, read in a 3D-rendered file of the blimps, and then combine the New York City image with a hand-painted Z image (of the New York City image).

The RGB images:

The depth images:

The blimp mask and final composite:

Why use ZCompose? With nearly 100 ships in the air, you have to recreate the cityscape in 3D and create a 3D mask in the render. The most practical solution is to move the camera, however, since the background plate in this example is static, fake the Z with a hand-painted mask of the New York City image. By using Z, the dirigibles appear in front and behind the buildings, as shown in following close-up image.

To start the Z composite, read in the tutorial images using one of the following:

  • Start Shake, and create a FileIn. In the Load image or sequence browser, navigate to doc/pix/nyc. Shift-click dir.iff , nyc.jpg, and nyc_grey.jpg, and click OK.

    Note: Shift-click allows you to select multiple files within the same directory. You can also drag-select.

  • Be a geek and use the Terminal to start Shake. Navigate to doc/pix/NYC, and type:

    shake dir.iff nyc.jpg nyc_grey.jpg
    -gui
You have a disturbingly complex (but oddly soothing) tree that looks like the following, more or less.




Peeking at the Z Channel

First, a bit of image framing:

Shift+F ensures that the Viewer title bar is visible. The Viewer title bar displays information about the image. For example, the dir image is a BWAZ (black-and-white image, with alpha and Z channels) 8-bit image.

Now you are probably thinking, "Great, I just press Z and see the Z channel." Well, that would be dandy, and obvious, but it sadly isn't so. Shake does not know what to show you that accurately displays your image sequence, as your Z values may zoom toward or away from the camera over the course of the sequence. For example, a plane could be flying towards the camera, so Z values would change every frame.

To view the Z channel of an image:

The Z values for your image are determined and displayed. This is an old Alias-rendered image, so the actual Z values go from 0 to around 270.

Not the most elegant method, but it works. Here, Original and Distance return the same value. However, if you use a 3ds max or a Maya-rendered image, you get negative values and -1/distance values, respectively, which are not intuitive. Setting the Z View ViewerScript to Distance returns the actual distance from the camera.

A note about the Z View: It is non-intuitive in that it displays low values (objects close to the camera) as white. Objects which have greater Z values (objects far from the camera) are given darker values. This is the opposite of how you associate high numbers and image values, but it allows Shake to display distant objects as fading into the infinite distance properly.

Does the Z View sound like it's cobbled together with electrical tape? You're right, it is!

Preparing the Z Channel for the City

You must prepare the false (hand-painted) Z channel for the New York City image to be copied over as a proper Z channel. Whereas the dirigible element has a specific Z channel with ranges from 0 to approximately 262, in this case you must copy the painted black-and-white image as the simulated Z channel. The only difference is that the values of this channel, since it is 8-bit, range from 0 to 1.

Use the Reorder node to copy the red channel of the painted image into the Z channel.

You have now created a snazzy Z channel. Next, use a Layer - Copy node to copy the Z channel to the NYC image.

To copy the Z channel to the RGB NYC image:

One last step, small and easily forgotten.ZCompose needs alpha channels in the images, and the NYC image doesn't have an alpha channel.

Creating the ZCompose

Since the Z channels are in place, you can now create the Z composite with a ZCompose node. The ZCompose function takes two images, and promotes the RGBA pixels by comparing which image has the lower Z value. Therefore, order does not matter with a ZCompose.

And... Nothing happens!

OK, after all of that buildup, you are crushed and manically disappointed to see that the composite is only of the city—no airships in sight. Great. What a fine tutorial.

If you recall, the dirigible (dir image) Z values range from 0 to approximately 262, as shown earlier with the Pixel Analyzer. The NYC range is from 0 to 1. That pretty much guarantees that the NYC image is always going to be in front of the blimps, since 1 is less than, say, 130. You must therefore multiply the Z value of the city to scale it to match the Z range of the blimps.

The Mult node has a parameter called depth. It is used to multiply, um, the depth. In the Mult parameters, there are three ways to modify the depth parameter:

Things start to look mighty keen once you get past 70, and triumphantly swell around 190.

Applying a Color Correction

You may have noticed that, gee, the blimps are black and white in the middle of a fine smoggy red sunset. Blend them into the scene with a Compress node. This is a good node for fog effects, and for matching color ranges.

The Compress node squeezes the blacks and whites into a colored range.

The entire image is brightened because you are color correcting a premultiplied image. By raising the black levels, the entire image, including the space between the blimps, is raised. As discussed in the Intermediate tutorial, use the following solution:

The color correction appears only on the blimps.

Next, set the higher colors.

The blimps blend with the New York City image.

Ganging the Color Pickers: To gang the three values in the color picker together, hold down the O key (for Offset) and click-drag left and right over the numbers. You can also use S (saturation), H (hue), T (temperature) and other similar channel keys, such as L, R, G, B.

Adding Fog to the Dirigibles

Without Fog With Fog

In this section, add depth cueing by color correcting the blimps in the foreground differently than the blimps in the background. There are about 300 ways to do this, but here, pull a depth-based key from the dir image and use it as a mask for the Compress1 node.

As an alternative, connect MMult1 to a Layer - KeyMix node. The DepthKey is the third image input, and whatever else you want (a colored Ramp, a differently color-corrected blimp, etc.) is the second input in the KeyMix node.