Log Color in-depth

log equation

Every professional camera manufacturer and almost every VFX and grading package has a Log workflow. Camera companies such as Arri, Sony, Canon, Red and many others implement their own flavors of Log color space. With the Log workflow it is possible to fit more dynamic range into an image and simulate nonlinear film response to light. The term Log is derived from the word logarithm, which is a fancy name for a function which outputs exponents for the given number.

For example, the equation 3^2=9 can be expressed as log3(9) = 2. In other words, if we want to find X in the expression 3^X = 9, the log function will output the value of 2. Pretty straightforward huh?

So what do logarithms have to do with beautiful pictures and cameras? Why do so many people use them and why they call this thing Log? Let’s start of with some Log curves pictures from Arri Alexa, Red and Canon.log curve cameraThough each curve is unique, it is clear that all of them have similar profiles. And this is because the curves derive from the mathematical function y=log(x)

I remember the days when I was working with film and it was all Cineon Log. Film labs and high end post-production facilities were the only places where the Log color space was used and very few people could understand its use. Nowadays, even consumer cameras like GH4 and Sony a7s come with Log color profiles. Since the technology is all over the place, wouldn’t it be great to have a more in-depth look at the tech?

ArriScan Log film gamma 2 linear

Here is a beautiful ArriScan log film plate back from my days in post-production. To download the original DPX film plate click here.

First of all, the read will have some basic math, but nothing fancy. After understanding the principals behind Log curves, you would be able to design and approximate any Log and Linear color profiles for any camera. Let’s begin.

I wanted to find out how a logarithm was used to encode an image into the Log color space. It turned out to be very simple. I opened my favorite VFX compositing app Fusion and created a greyscale gradient image with a custom tool node where I could write mathematical expressions to change values of pixels.

exp start

I started from the gradient image. The math expressions can be looked up on the right.

I knew that I needed to plug RGB values into a log function to obtain a basic log curve. So, I wrote an expression log(r1) for red channel and log(g1), log(b1) for green and blue channels respectively. This is what I had:

exp below zero

RGB values were plugged into a log function. I got a negative curve and a black image.

My log curve was below zero, which resulted in a black image. For a couple of seconds, I was confused that my log curve created negative values. Then I realized that Fusion measured the values of pixel from 0 to 1 for normal RGB values and from 1 and above for HDR values. Since my gradient image was gradating from 0(black) to 1(white), and logarithm always produces negative output for the values between 0 and 1, it was natural that I would end up with the curve below zero. In order to bring my values to a positive range I added 1. After addition the new positive range was between 1 and 2.

exp whole numbers

After bringing the curve into the positive domain. The log function produced a low range image.

Although, my curve was above zero, it was flat and didn’t look like other camera log curves. That was due to the fact that new values of 1 to 2 are too small to produce a nice log style rolloff. To fix this I needed to widen the domain of the input values. I multiplied the RGB values by 100 to move the output values to a higher range.

exp super bright values

The values are widened creating a super bright high range image.

The next thing was to compress the values to a Cineon range. The gain(multiplication) operation helped to bring the highlights down and offset(addition) operation brought the black level up. I had a curve that almost perfectly matched a Cineon film Log.

exp end

The final Cineon Log curve.

two log curves

I deliberately mismatched the curves so it was easier to identify them. And finally, here is a visual comparison between the custom Log and a Cineon Log curve. I took a raw frame from an indie music video I’ve shot a year ago. The encoded image can be graded and used in conjunction with other Log LUTs. So, in order to create a Cine style Log profile all we need to do is to use the function log(r1*n3+1)*n1+n2. Where r1 is a value of a channel, n3 is a user parametric value for widening the values range, n1 is a gain parameter and n2 is an offset.

log formula

comparison_maydees

I successfully encoded the raw image into Log color space. However, the real fun was when I decided to bring my Log image back into Linear color space. I could use the default Log to Linear conversion and it would work perfectly, but I wanted to perform Log to Linear conversion mathematically.  It took me a while to figure out the process, but after all it was very easy. All I needed to do was finding the inverse function of the log function. Employing simple algebra concepts, I managed to create another node which handles Log to Linear conversion. Here is how I found the inverse function:

inverse log

n is a gain parameter, w is an offset, 100 widens the values. The log reverse function is a power function.

log-to-lin-conversion

Now, it is possible to approximate any camera Log profile or create a brand new Log and Linear style curves. Using the same function, I easily approximated Arri LogC and Canon-Log profiles.

arri canon logs match

The red curves are slightly misplaced for displaying purposes.

In conclusion, to bring an image into the log color space all we need to do is to apply a logarithmic function which transforms values of pixels based on the log curves above. To linearize a log picture, we use an exponent function. Since the log color space is a mathematical transformation of values of pixels, it can be used with any types of file format, bit depth and channel. Moreover, the log color space is used in video games. Many video game developers use log to encode zdepth buffers. This is it! Hope it was useful! And don’t forget to download the DPX film plate I shared above. You’ll notice how differently the film responds to color adjustments. To get the latest blog updates follow @renderstory

2 thoughts on “Log Color in-depth

  1. Fantastic analysis! This is the kind of thing I love to see.

    I had assumed that there was some kind of dark magic in the camera-specific log curves; it’s nice to see them broken down so clearly here.

Leave a Reply

The reply will be processed within a day