Publishers of technology books, eBooks, and videos for creative people

# Nuke 101: Color Correction

• Print
This chapter is from the book

## Color Matching with the Grade Node

The Grade node is specifically built to make some color correction operations easier. One of these operations is matching colors from one image to another.

When matching colors, the normal operation is to match black and white points between the foreground and background (only changing the foreground), and then match the level of the midtones gray, and finally match the midtone hue and saturation.

The Grade node is made out of a few of the building blocks mentioned earlier. TABLE 4.2 shows a list of its seven properties.

#### Table 4.2. Grade Node Properties

 Property Definition Blackpoint This is the reverse operation to Lift. It works in the same way, but higher numbers will result in stronger blacks instead of lighter blacks. Basically, the color chosen here will turn to black. Whitepoint This is the reverse operation to Multiply. It works in the same way, but higher numbers will result in lower highlights instead of stronger highlights. Basically, the color chosen here will turn to white. Lift A Lift operation. Gain A Multiply operation. Multiply Another Multiply operation. Offset An Add operation. Gamma A Gamma operation.

By using Blackpoint and Whitepoint to set a perfect black and a perfect white, you can stretch the image to a full dynamic range. When you have a full dynamic range you then can easily set the blackpoint and whitepoint to match those of the background using Lift and Gain. You then have Multiply, Offset, and Gamma to match midtones and for final tweaking.

Let's practice color matching, starting with a fresh script.

1. If you want, you can save your script. When you are finished, press Ctrl/Cmd-W to close the script and leave Nuke open with an empty script.

2. From your chapter04 folder bring in two images: CarAlpha.png and IcyRoad.png.
3. Make sure that CarAlpha.png is called Read1 and IcyRoad.png is Read2. You can change the name of a node in the top-most property.

You will quickly composite these images together and then take your time in color matching the foreground image to the background.

4. Select Read1 and press the M key to insert a Merge node after it.
5. Connect Merge1's B input to Read2 and view Merge1 in the Viewer (FIGURE 4.21).

The composite is almost ready. You just need to punch a hole in the foreground car so it appears to be behind the snow that's piling on the windshield. For that, you'll bring another image in (you will learn how to creates mattes yourself in Chapter 6).

6. From your chapter04 folder bring in Windshield.png and display it in the Viewer.

Here you can see this is a matte of the snow. It is a four-channel image with the same image in the R, G, B, and alpha. You need to use this image to punch a hole in your foreground branch. To do that you will need another Merge node.

7. Select Read3 and insert a Merge node after it.
8. Drag Merge2 on the pipe between Read1 and Merge1 until the pipe highlights. When it does, release the mouse button to insert Merge2 on that pipe (FIGURE 4.22).
9. View Merge1 (FIGURE 4.23).

You can see here that this is not the desired result (FIGURE 4.23). You still need to change the Merge2 operation to something that will cut the B image with the A image. This operation is called Stencil. Stencil is the reverse operation from Mask, which you used in Chapter 3. Mask held image B inside the alpha channel of image A, and Stencil will hold image B outside image A.

10. In Merge2's Properties panel, choose Stencil from the Operation drop-down menu.

Looking at your comp now, you can see that it works—short of a color difference between the foreground and background (FIGURE 4.24). Let's use a Grade node to fix this shift.

11. Select Read1 and press the G key to insert a Grade node after it.

As you know from Chapter 2, you are not allowed to color correct premultiplied images. It is often hard to tell if an image is premultiplied or not, but in this case it is. You can also look at the RGB versus the alpha channels and see that the areas that are black in the alpha are also black in the RGB.

Since you can't color correct premultiplied images you have to unpremult them. You can do this in one of two ways: using an Unpremult node before the color correction (in this case, Grade1) and then a Premult node after it, or using the (Un)premult By Switch in your Color nodes. Let's practice both.

12. Bring Grade1's Offset property up to around 0.4.

You can see that the whole image, except the dashboard area, turned brighter, even though you are only correcting the car image (FIGURE 4.25). This is due to the lack of proper premultiplication. Let's do the two-node method first.

13. Click Read1 and from the Merge toolbox add an Unpremult node.
14. Click Grade1 and from the Merge toolbox add a Premult node and look at the Viewer (FIGURE 4.26).

The problem has been fixed. This is one way to use proper premultiplication. Let's look at another.

15. Select Unpremult1 and Premult1 and press the Delete key.
16. In Grade1's Properties panel, choose rgba.alpha from the (Un)premult By menu; this automatically selects the associated check box (FIGURE 4.27).

The resulting image looks exactly as before (Figure 4.26). This technique does exactly the same thing as the first method, just without using other nodes. I usually prefer the first method as it shows clearly in the DAG that the premultiplication issues are handled. However, if you look at Grade1 in the DAG now, you will see that, although a smaller indication, Grade1 is showing that it is dividing the RGB channels with the alpha channel. The label now says "rgb/alpha" (FIGURE 4.28).

Let's use the second method you have set up already. You will now be color correcting an unpremultiplied image, but outputting a premultiplied image. After a little rearranging, the tree should look like that in FIGURE 4.29.

17. Bring the Offset property back to 0.

### Using CurveTool to match black and white points

Thinking back to the introduction of this section, how are you going to find the darkest and lightest points in these two images to match them together? One way, which is valid and happens often, is using your eyes to gauge which are the darkest and brightest pixels. However, the computer is so much better at these kinds of things, and doesn't have to contend with light reflections on the screen, etc.

The Node to use for this is the CurveTool node, which you used in Chapter 3 to find the edges of the lemming element. You can also use this node to find other color-related stuff about your image. Let's bring a CurveTool node in to gauge the darkest and brightest point in the foreground and use that data to stretch the foreground image to a full dynamic range.

1. Select Read1 and branch out by Shift-clicking a CurveTool node in the Image toolbox.

This time you are going to use the Max Luma Pixel Curve Type. This finds the brightest and darkest pixels in the image.

2. In CurveTool1's Properties panel, switch the Curve Type drop-down menu to Max Luma Pixel.
3. Click the Go! button.
4. In the dialog box that opens, click OK as you only want to process one frame.
5. Switch to the MaxLumaData tab and view CurveTool1 in the Viewer (FIGURE 4.30).

The purpose of this operation is to find the darkest and lightest pixels in the image. When switching to this tab you see two sections, the one showing the lightest pixel (Maximum) and the darkest pixel (Minimum). For each, the X and Y location and RGB values display.

Looking closely you can see that the value of the minimum pixel is 0 in every property. This is because this image is a premultiplied image, and as far as CurveTool is concerned, all that black in the image is as much a part of the image as any other part of it. You need to find a way to disregard that black area. Let's do the following.

6. From the Image toolbox, create a Constant node.
7. Change Constant1's Color value to 0.5.
8. Select Read1 and branch a Merge node from it by pressing Shift-M.
9. Connect Merge3's B input to Constant1, and then view Merge3 in the Viewer (FIGURE 4.31).

What you did here was replace, momentarily, the black background with a middle gray background. This way you are getting rid of the black and replacing it with a color that is not the darkest nor the lightest in the image. This new image is the image you want to gauge using the CurveTool. You'll need to move the pipe coming in to CurveTool1 (FIGURE 4.32).

10. Click the top half of the pipe going into CurveTool1, which will enable you to move it to the output of Merge3.
11. Double-click CurveTool1 to display its Properties panel in the Properties Bin.

Switch to the CurveTool tab (the first one), click Go! again, and click OK.

12. Switch to the MaxLumaData tab again and have a look (FIGURE 4.33).

You can see now that the minimum values are far from being all 0. You are now getting a true result showing the lightest and darkest pixels. Let's make use of them.

13. Close all Properties panels in the Properties Bin to clear some room.
14. Double-click CurveTool1, and then double-click Grade1.
15. View Merge1 in the Viewer.
16. Click the 4 icon next to Grade1's Blackpoint, Whitepoint, Lift, and Gain to enable the four fields.
17. Ctrl/Cmd-drag from CurveTool1's Minimum Luminance Pixel value's Animation menu to Grade1's Blackpoint Animation menu and release the mouse button to create an expression link between them.
18. Do the same from Maximum Luminance Pixel value to Whitepoint (FIGURE 4.34).

The foreground image's dynamic range now spans from a perfect black to a perfect white. This enables you to push those colors to new black and white points to match these points to the background image. You'll need to use another CurveTool to find those points in the background image.

19. Click Read2 and by Shift-clicking, branch out another CurveTool from it.

This time there is no alpha and no black background to worry about. You can simply proceed to finding the black and white points.

20. In CurveTool2's Properties panel, choose Max Luma Pixel from the Curve Type drop-down menu.
21. Click Go! When asked, click OK.
22. When the processing is finished (you should see a quick flash of the Progress Bar) switch to the MaxLumaData tab.

You now have two sets of data to match to: new black points and white points. Let's link them to your Grade node.

23. Close all Properties panels in the Properties Bin to clear some room.
24. Double-click CurveTool2, then double-click Grade1.

26. Do the same from the Maximum Luminance Pixel value to Gain (FIGURE 4.35).

You have now matched the foreground's shadows and highlights to those of the background (FIGURE 4.36).

As you can see from the image, the shadows and highlights are matched, but the image is far from looking matched. The midtones, in this case, make a lot of difference.

### Matching midtones by eye

You now need to match the midtones. This is a much more difficult task. You'll start by matching its luma level by eye. Because it is hard to tell what the midtones are, though, you are going to view the luminance of the image in the Viewer.

1. Hover your mouse pointer in the Viewer and press the Y key to view the luminance.

To change the midtones now, you will use the Gamma property. You can see that the whitish snow on the right is a darker gray than the whitish car. Let's bring down the whitish car to that level.

2. Start dragging the Gamma slider down. I stopped at around 0.6.

Notice that the midtones don't match well with a higher Gamma value. Now, however, the lower midtones aren't matching well. I need to use the Multiply property to produce a good match.

3. Bring the Gamma slider up to 0.85 and bring the Multiply slider down a bit to 0.9 (FIGURE 4.37).

4. Hover your mouse pointer in the Viewer and press the Y key to view the RGB channels (FIGURE 4.38).

OK, so the midtones' brightness is now better, but you need to change the color of the car's midtones. At the moment, the car is too warm for this winter's day. Matching color is a lot more difficult as you always have three options: red, green, and blue. Matching gray is a lot easier as you only need to decide whether to brighten or darken it. However, as each color image is made out of three gray channels, you can do that to match color too. Here's how.

5. Hover your mouse pointer in the Viewer and press the R key to view the red channel (FIGURE 4.39).

Now you are looking only at levels of gray. If you now change the red sliders, you will better match the color while still looking only at gray.

6. Display the Color Wheel and Color Sliders panel for the Gamma property by clicking the Color Wheel button.

You will also want to change the Multiply and Offset values to achieve a perfect result. This is because, even though you matched the black point and white point, the distance of the car from the camera means the black point will be higher and the white point lower. At the end of the day, it will only look right when it does, math aside.

Let's display those extra color wheels.

7. Ctrl/Cmd-click the Color Wheel button for the Multiply and Offset properties. Your screen should look like FIGURE 4.40.
8. Since you are looking at the red channel in the Viewer, you should change the red sliders for Gamma, Multiply, and Offset until you are happy with the result. Little changes go a long way. I left mine at Gamma: 0.8, Multiply: 0.82, and Offset: 0.02.
9. Display the green channel in the Viewer, and then move the green sliders to change the level of green in your image. Mine is Gamma: 0.85, Multiply: 0.95, and Offset: 0.025.
10. Do the same for the blue channel. Mine is Gamma: 0.96, Multiply: 0.95, and Offset: 0.03.
11. Switch back to viewing the RGB channels (FIGURE 4.41).

This is as far as I will take this comp. Of course, you can use your already somewhat-developed skills to make this a better comp, but I'll leave that to you.

Save your script if you wish, and we will move on.