ColorCorrect

The ColorCorrect Node

Shadows, midtones, highlights and the maths that blends them

Math in Nuke, the series: Merge & Premultiplication · The Grade Node · ColorCorrect · Saturation, Hue & HSV · Keying · Despill · Matching Colour & Light · Edge Extend · Lin, Log & Gamma · Filtering & Resampling · Edge Detection · Vectors · Trigonometry · Expressions & Curves

The ColorCorrect (shortcut C) looks like four Grades in one: master, shadows, midtones and highlights, each with saturation, contrast, gamma, gain and offset. Foundry doesn't publish its source code like it does for the Grade, and the documentation doesn't give the formulas. So I measured it: I ran Nuke 17 from the command line, fed known values into a ColorCorrect, read the results back and found the formulas that match them to six decimals. Everything on this page comes from those measurements.



Useful Links



Index



01. Four groups, five knobs

Every group, master, shadows, midtones and highlights, has the same five knobs: saturation, contrast, gamma, gain and offset. The script names are saturation, contrast... for master and shadows.gain, midtones.gamma, highlights.offset and so on for the others. Gain is a multiply, offset an add, gamma a power, as in the Grade. Saturation and contrast are new, and contrast hides the biggest surprise of the node.



02. What is a shadow? The ranges

The node computes the luminance of every pixel of the input, with Nuke's Rec.709 weights:

L = 0.2125 r + 0.7154 g + 0.0721 b

and looks it up in the curves of the Ranges tab. I read the default curves point by point: they are two smoothsteps, exactly.

shadows = 1 − smoothstep(0, 0.09, L)
highlights = smoothstep(0.5, 1, L)
midtones = 1 − shadows − highlights

00.10.20.5100.51luminanceweightshadowsmidtoneshighlights
The default ranges, read point by point from Nuke 17. The three weights always add up to 1.

That's why Foundry warns you never to edit the midtones curve: it's the remainder. In scene linear, 0.09 is only about one stop below middle grey: the "shadows" are the deep darks, and almost everything is a midtone. Everything below 0 is 100% shadow, everything above 1 is 100% highlight.

The test checkbox is cleverer than it looks. The green channel shows the smooth blend (0 for shadows, 0.25 for midtones, 1 for highlights, mixed with the weights), while red and blue show only the range that wins. Where two ranges overlap, the two disagree: the shadows-to-midtones zone comes out magenta, the midtones-to-highlights zone green. Those tinted bands are exactly where the blending happens.



03. The order of the knobs

Inside the node the knobs always run in this order, I checked every pair:

saturation → contrast → gamma → gain → offset

- saturation: L + s × (colour − L), with the weights above. Nothing is clamped: a saturation of 2 can make a channel negative.
- contrast: a power around a pivot (next chapter).
- gamma: x1/gamma for every value above 0, also above 1.
- gain: x × gain.
- offset: x + offset.

The gamma is the first big difference from the Grade: there a gamma of 2 sends 3 to 2 (a straight line above 1), here it sends 3 to 1.73. On bright CG the two nodes give different results with the "same" gamma.



04. Contrast, and its three pivots

A gamma pivots around 1: lowering it darkens everything below 1. The contrast moves the pivot: scale so that the pivot becomes 1, apply the power, scale back.

out = (in / pivot)contrast × pivot

For master the pivot is 0.18, middle grey, as Gene Hammond-Lewis described on The Compositor Mathematic. But the measurements show that every range has its own pivot:

groupcontrast pivot
master0.18
shadows0.04
midtones0.18
highlights0.65
000.20.40.70.8100.20.40.60.811.2inputoutput, contrast 1.6unchangedshadows, pivot 0.04master and midtones, pivot 0.18highlights, pivot 0.65
The same contrast of 1.6 around the three pivots. Each curve crosses the straight line at its own pivot: below it values go down, above it they go up.

It makes sense: each range pivots around a value that lives inside it, so shadows.contrast stretches the darks around a dark value and highlights.contrast the brights around a bright one.

A negative number can't go through a power, so values at or below 0 skip contrast and gamma. Instead Nuke multiplies them by the number that 1 becomes after contrast and gamma: a straight line through 0.

in ≤ 0:   out = in × T(1)    (T = contrast and gamma)
master contrast only:   out = in × (1 / 0.18)contrast − 1

With gamma alone 1 stays 1, so negatives are untouched. With contrast they're not: careful with shadows.contrast on plates with negative grain, because with the 0.04 pivot a contrast of 2 multiplies them by 25.



05. How master and ranges are combined

Every pixel is corrected three times, once for each range, and the three results are mixed with the weights of chapter 02. The master is not applied before or after: it's woven into each range, knob by knob. For a range group the chain is:

saturation (range × master) → contrast (range, then master) → gamma (range × master)
→ gain (range × master) → offset (range + master)

out = shadows(x) × s + midtones(x) × m + highlights(x) × h

So a master gain of 2 with a midtones offset of 0.1 gives 2x + 0.1, not 2(x + 0.1): the master gain comes before the range offset, because gain comes before offset. Natron's open-source ColorCorrect, which I used before measuring, applies the master after the blend and uses 0.18 as the pivot for every range: close, but not the same.

Two practical consequences. The weights come from the luminance of the input, so a strong correction in the shadows can't push a pixel "out" of the shadows. And where the curves are steep, big differences between the groups give visible bands: keep the range corrections gentle and do the big moves in master or in a Grade. The ranges are absolute luminance values, so they don't follow exposure: double the exposure and the same object can move from shadows to midtones.



06. ColorCorrect or Grade?

Grade for anything technical: matching black and white levels, balancing a plate to a reference, exposure, anything you might reverse. Its maths is published, simple and reversible.
ColorCorrect for quick creative moves and when you need saturation, contrast around grey or a correction limited to the darks or the brights. Remember the two traps: its gamma is a true power above 1, and every range has a different contrast pivot.



ColorCorrect Lab

This Lab runs the model above: the measured range curves, the three pivots and the master woven into each range. Choose a group, move its knobs, and switch on test to see the ranges (look for the magenta and green bands). The small plot shows the weights against luminance and, dashed, the contrast pivots.

Original ColorCorrect


Nodes to paste in Nuke

Click a box, copy it (Ctrl+C / Cmd+C) and paste it in Nuke's Node Graph (Ctrl+V / Cmd+V).

Ranges preview. Shows in red, green and blue how much every pixel belongs to shadows, midtones and highlights, with the default curves of chapter 02.

The master group, rebuilt. An Expression that does exactly what the master knobs of a ColorCorrect do (with the ranges untouched): put it next to a real ColorCorrect with the same values and subtract them.

Contrast with your own pivot. The contrast formula of chapter 04, but with the pivot in the User tab.



The math series

The other pages about maths in Nuke:
Merge & Premultiplication The Grade Node Saturation, Hue & HSV Keying Despill Matching Colour & Light Edge Extend Lin, Log & Gamma Filtering & Resampling Edge Detection Vectors Trigonometry Expressions & Curves
And if you like this, have a look at the Matrices in Nuke series.

Leave a comment