Is Colour Science Just Simple Math That Excel Can Do?

December 15, 2022
Is Colour Science Just Simple Math That Excel Can Do?
Posted in: All Film Science
Better films every fortnight. Subscribe to Syrp Lab YouTube.

Is colour science just simple math? So simple that you can grade an image in Excel using basic equations? We find out by going under the hood of Davinci Resolve. And no, your accountant is not going to be grading your next film.

To build Resolve in Excel first we need to understand colour – or more accurately, how screens, video and the digital world understand colour.

We’re going to assume you know images are made of pixels and each of those pixels is made of a red, green and blue sub-pixel and the brightness of each of those sub-pixels combines to make any colour. If you didn’t, now you do.

Because each pixel is just a numerical set, we can do the math to those values changing the pixel and the whole image. 

If we take a single pixel from a frame of Chase’s face, for example, its value in red, green and blue is 231,170 and 152, combining together to create this fleshy pink. If we times each of those values by 1.1 we get 254, 187 and 167 making the pixel the same “colour” just brighter. And congrats we've just discovered the concept of gain. We’re taking our values and increasing them all by 10%.

Which makes complete sense right, it’s not really that complicated at all – we’ve just never really thought about the math behind the tools we use to adjust images.

By understanding how these fundamental functions work, we could probably become better at grading. So if Gain is so simple – what about the others? Could we write out all this math in excel and build a clone of Resolve?

 

Building the Excel RGB workbook

The first step was to work out how to get this image into excel – not just as a JPG but as individually coloured cells we could modify. Matt wrote a tool in Nuke that created a list of the RGB values of each pixel, but it was slow… like… 3 hours for a single frame slow!

So we grabbed one of our resident interns Jack and rewrote it in python to give us an enormous list of values we could work with.

We then brought those into excel, and when arranged in their cells and you could almost kinda see an image. But we need colour from these numbers, so we adjusted some code from Stack Overflow posted by Tim Williams that turned our three values on one sheet into a coloured cell on the other and then did that again and again and again 22,399 times – Thanks again Tim, really!

Finally with the additions of some fancy Pie charts we have… the most unstable excel workbook in existence… but it works. You can download and try it out for yourself here.

How it all works

So we’ve built our gain control formula already, increase the gain and increase the brightness evenly across the whole image by the same percent. And to do that we’re just multiplying all the values. But what about the other controls?

The best way to understand all transforms is a graph where on the X axis we have our input value and on our Y axis, we have the resulting output. While Gain changes the slope of the graph by pivoting around 0,0, Lift changes the slope of the graph by pivoting around 1,1. This means, gain makes a value bigger the closer to 1 it is and Lift makes a value bigger the closer to 0 it is. Getting lost? Don’t worry the video below illustrates this all visually.

Contrast works in a similar way - it just takes the graph and multiplies it based on a pivot, making the brights brighter and the darks darker. And we can adjust where this pivot or crossover point is by changing the pivot value. As a side note, the contrast in resolve has roll-off softening the clipping.

All of these are multiplications, but what about addition, for that, we have offset, which sifts an image up or down, but keeps the same slope. Resulting in an image that is brighter but looks a bit faded. If we were to write that in math it would be Input + Offset.

We can also get a bit more advanced with Gamma which adds a curve to our graph, which means we can shift our mid-tones while not impacting the upper and lower ends too much.

We can even just take the graphs of different channels and shift them with gain to correct the white balance – this is how we change colour temperature. And we are doing all these adjustments by applying a simple equation to our red, green and blue values in Excel.

 

Hue, Saturation and Luminance

But unfortunately, this is kind of the limit of what we can do here in Excel because the colour doesn’t just exist in this RGB space, we can also do a whole other world of transformations by visualising or expressing the colour completely differently – using something you've probably heard of, Hue, Saturation and Luminance (HSL).

When we visualise colour in RGB it’s easy to think about our volume of possible colours as a cube with each colour sitting on one of the axes. When it comes to HSL, it’s easier to understand as a cylinder. Luminance is our up and down, how bright a colour is, Saturation is our in and out, how colourful the colour is and our final axis is more of a circle, which hue or part of the rainbow our colour is. 

 

This model opens a whole bunch of new possibilities for grading where we can adjust in a way that wouldn't be possible with our RGB tools.

Where RGB has a red, green and blue channel we can modify; HSL has a hue, saturation and luminance channel we can adjust. The thing to remember is that these channels are still just a collection of numbers that can be modified with math.

If we take Hue as a spread from 1-360 degrees, we can take groups of numbers and shift them up, down or somewhere else entirely changing the colour of objects in our shot. We can also use curves to pull colour numbers toward another colour resulting in something a bit more subtle. With this, we can create shots that feature complementary colour pallets and change the mood or feeling of a scene like the classic teal and orange. And of course, we’re not limited to modifying just that one channel, we can also reduce or increase the saturation and luminance channels. Or even use one channel as a qualifier for the other meaning we can change the saturation of pixels if they’re a particular hue. 

 

Spacial Adjustment

But back to Resolve, there’s also a final third space of adjustments – transforms that are spatial – or to explain better, transforms that aren’t on a pixel-by-pixel basis, but rather mix the information from neighbouring pixels too. The most common is the highlights and shadows sliders. Resolve is essentially pulling a luma key of the shadow region, blurring the mask - which takes into consideration all the neighbouring pixels, which then allows you to gently adjust the gain. This way you can lift the shadows without removing all contrast and muddying the image.

We can build a similar tool ourselves with nodes but it’s much more convenient to just use it how it was built. The thing is, Resolve is a bit of a magic box and we can’t see exactly what it’s doing – only that it’s doing a pretty great job of these special adjustments.

Receive our latest videos and participate in camera gear giveaways

We send a newsletter once or twice a month and we make it easy to unsubscribe at any time.

Colour Spaces

Ok but all of these sliders and tools exist in every other editor, why do they feel so great in Resolve. 2 factors:

1. Resolve has great colour management and the ability to work in linear colour spaces like ACES. When working in Rec709, we have a non-linear gamma curve that is already applied to our footage that maximises the perceivable range (watch our video on Log vs Raw if you have no idea what I'm talking about). If we do adjustments in this space, we're stacking curves on existing curves, the tools are functioning less accurately than if we were operating in pure linear in a colour space.

2. The developers of Resolve have spent a lot of effort making these controls feel accurate and great. While they operate on the basic math we used, there are a few other processes going on in the background of these tools that make them smarter and more nuanced than our simple graphs.

This all combines with power windows tracking and a whole suite of other tools to make resolve exceptionally powerful – much more so than we could recreate in excel. But now we have a better understanding of how it all works, we think this enables you to become even better at grading.

You can download our Excel Image Grader and a Resolve project where you can see what each Resolve Function is doing here.

 

For a further deep dive into the science behind filmmaking we highly recommend starting here What's the difference? LOG vs RAW footage for colour grading

Curious about the gear we used to make this episode, here’s our complete kit:­

Rycote Shotgun Mic

Rycote Windshield

Audix A131

Quasar Science Rainbow 2

JOBY GorillaPod 5K

Gemini 1x1 Lightpanels

Manfrotto Fast Twin Leg Carbon

Canon C200 Camera

 

December 15, 2022

Vitec Group
  Our Brands