Applying Mathematical Operations

Nuke’s Color icon in the Toolbar houses a number of nodes which are designed to apply common mathematical operations to channels. These operations include clamps, offsets, inversions, multiplications, and expressions.

Clamping Channel Values

To clamp a channel’s values is to ensure that its blackest blacks and whitest whites are visible on an intended display device. Nuke’s Clamp node lets you assign “legal” values to colors that are either too light or dark for the intended display device.

Clamping black and
white pixels to “legal” values.
Clamping black and
white pixels to “legal” values.

For this effect, you use Nuke’s Clamp node.

1.   Click Color > Clamp to insert a Clamp node at the appropriate point in your script.
2.   Connect a Viewer to the output of the Clamp node so you can see the effect of your changes.
3.   In the Clamp properties panel, use the channels field to select the channel you wish to clamp.
4.   Drag the minimum slider to the legal value. (This has the effect of causing black values to go gray.)
5.   Drag the maximum slider to the legal value. (This has the effect of causing white values to go gray.)

Offsetting Channel Values

To offset a channel’s values is to add a fixed value to them, which, in effect lightens the whole channel. You can also add a negative value to a channel, in which case the channel gets darker.

Offsetting channel values. Offsetting channel values.

For this effect, you use Nuke’s Add node.

1.   Click Color > Math > Add to insert a Add node at the appropriate point in your script.
2.   Connect a Viewer to the output of the Add node so you can see the effect of your changes.
3.   In the Add properties panel, use the channels field to select the channel you wish to offset.
4.   Use the value slider to input the value you wish to add to the channel’s values.
5.   If you are using premultiplied input images, you may want to check (un)premult by and select rgba.alpha from the dropdown menu. This simulates doing the addition before the premultiplication was done.

Inverting Channel Values

To invert a channel is to subtract its values from one, which causes its blacks to become white and its whites to become black. In the course of building a script, you’ll have frequent need to invert mattes in particular.

Inverting channel values. Inverting channel values.

To invert channels you use Nuke’s Invert node.

1.   Click Color > Invert to insert an Invert node at the appropriate point in your script.
2.   Connect a Viewer to the output of the Invert node so you can see the effect of your changes.
3.   In the Invert properties panel, use the channels field to select the channel you wish to invert.

Multiplying Channel Values

To multiply a channel’s values is to times them by a given factor, which has the effect of lightening the channel while preserving the black point. (This operation is also knows as gain.)

Multiplying channel values. Multiplying channel values.

For this effect, you use Nuke’s Multiply node.

1.   Click Color > Math > Multiply to insert a Multiply node at the appropriate point in your script.
2.   Connect a Viewer to the output of the Multiply node so you can see the effect of your changes.
3.   In the Multiply properties panel, use the channels field to select the channel whose values you wish to multiply.
4.   Use the value slider to input the factor by which to you want to times the channel’s values.

Applying Expressions to Channel Values

Up till now, the discussion has focused on how to apply simple mathematical formulae - additions, subtractions, multiplications, etc. - to a channel’s values. Nuke’s Expression node, however allows you to apply complex formulae to a channel’s values. The actual syntax for expressions is rather complex, and thus must be deferred to Expressions. For now, you can read about the basics of how to operate the Expression node.

1.   Click Color > Math > Expression to insert an Expression node at the appropriate point in your script.
2.   Connect a Viewer to the output of the Expression node so you can see the effect of your changes.
3.   In the Expression properties panel, use the channel dropdown menus and buttons to select the channel to which you wish to apply an expression.
4.   Type the actual expression in the = field next to the channel.

For example, to assign noise to the red channel, then boost the gain of that result by 20 you would type (random*r)*20.

5.   If necessary, you can apply different expressions to different sets of channels by repeating the above steps for the other channel dropdown menus and buttons.
6.   If you need to use a long expression in several fields, you can use the fields on top of the properties panel for assigning the expression temporarily to a variable. Enter your variable on the left side of the = sign, and the expression on the right. You can then use the variable to represent the expression in the = fields next to the channels.

A checkerboard modified using an
Expression node.