In this article we’ll learn what a Look-up Table (LUT) is, and how it should be used.
This article builds on the beginner articles in Color from the Learning Center. Please read them if you’re new to color, color models, color spaces, color channels and so on.
What is a LUT or Look-up table?
Ever seen a multiplication table in school? They wanted you to memorize the whole thing, but didn’t you wish you had the table with you whenever you were confronted with math?
It’s easy to remember 2 x 2 = 4, but try 196 x 314 or 457432 x 938483. What if you had a table that would let you find the answer instead of calculating it yourself?
In many ways, this is a look-up table, because if you want to find the answer to something, you just have to ‘look it up’. But you might be asking: That’s cool for humans, but aren’t computers super-fast in calculating?
Well, what is faster for humans is also faster for computers. Why wouldn’t you want to squeeze that extra juice from your four year old laptop?
What is a 1D LUT?
Your local pizza chain is robbing you blind. You feel they are reducing the pepperoni slices (substitute your favorite topping here) in your pizza. You look at their website, and they say: 18 slices per pizza, no matter what. A pizza is $18 – $1 per slice.
Their pizzas are square in shape, and they cut them into nine squares. You, being a math genius, figure out that each square must contain two whole slices of luscious juiciness. To show off, you write your wisdom this way:
The above is called a ‘matrix’ in math. Your pizza matrix ideally must look like that. Now, you know the actual pizza misses out, so you stay up all night to devise a devious formula. You are going to average all the boxes surrounding each box, and then average that with the box itself. Let me clarify:
- Formula A – for the corner boxes = [Actual Box Value + (Sum of values of the three boxes surrounding it)/3]/2
- Formula B – for the side boxes – [Actual Box Value + (Sum of values of the five boxes surrounding it)/5]/2
- Formula C – for the middle box – [Actual Box Value + (Sum of values of the eight boxes surrounding it)/8]/2
Your formula matrix looks like this:
If the perfect pizza matrix were to undergo a wash with your formula matrix, you’re supposed to get the pizza matrix again. Try it and you’ll see.
Armed with this magic wisdom, you call your local pizza store, and order a pepperoni pizza. “Will that be all, sir?”
“No. There’s one more thing. I think you’re short-changing me. You say 18 slices per pizza, but I never get that.”
“That is not true, sir. We always put in 18 slices.”
“Yeah, but what’s the point if the slices don’t have equal pepperoni? The person left with the lowest pepperoni-count slice is robbed. Therefore, I have devised a new formula…ahem…care to hear it?”
The owner hears you out, thinks for a bit and agrees! “All right, sir, you go ahead and apply your formula matrix on my pizza. You add whatever you get, and give me whatever total it comes to.
You have thirty minutes. Genius that you are, you create a quick iPhone app so you don’t have to waste time calculating each formula. Just take a picture and the app does the rest! After a thirty minute wait that seems like an age in Lord of the Rings, your pizza arrives. You open it, and the pepperoni slices are thus:
Ha! You quickly take a photo of the pizza with your iPhone app, it washes your pizza matrix with the formula matrix, and it gives you this result matrix:
Your hands shaking, you call the owner. “See? Your pizza is crap, my app is right!”
You can hear the owner sighing. “You got me, sir. You are way smarter than the average pizza eater. Just hand over the total of your matrix to the delivery guy. How much is the total anyway?”
You hadn’t put that in your app, so you bring out your calculator and….silence…the world crumbles around you. You have suddenly lost your appetite.
“Hello? Sir, are you there?”
$18.81. End of story.
The above matrices look two-dimensional but in fact they’re not. E.g., you could represent your values in a line instead of a matrix, like this: 1, 2, 1, 2, 3, 3, 5, 1, 0; and you could represent your formula in a line like this: A, B, A, B, C, B, A, B, A.
A line is one-dimensional, therefore, this formula matrix that you have created is a 1D LUT. Your iPhone app may as well be analogous to your graphics card, television, DaVinci Resolve or Red Giant LUT Buddy. So, here’s the general definition:
A LUT is a matrix that is applied on a set of values to transform them. This matrix can be a set of formulas (as in our pizza analogy) or a set of predetermined numbers (a color LUT).
The difference between a LUT and a formula is that a LUT always takes the appearance of a matrix, and can also be another set of values (as far as we are concerned, it is) instead of formulas. A 1D LUT is a one-dimensional matrix.
What is a 3D LUT?
Instead of pepperoni pizza, what if you ordered pepperoni+chicken+mushrooms pizza? Let’s say you are one of those annoying people who likes to pick and eat each topping one by one. First you pick a mushroom and pop it into your mouth, then you go for the chicken and then the pepperoni. Three dips, three trips to the mouth.
Or, you could just take one big bite.
I’m going to end the pizza analogy here, and revisit why LUTs exist in the first place: to save time on calculations. You are actually pre-calculating everything in advance so you won’t have to do it again and again. A 3D LUT reduces the number of calculations required.
If we need a 1D LUT for Red, then we also need two more – for Green and Blue. Each pixel has three values, R, G and B. You would need to manipulate the R, G and B values separately, one at a time. There is nothing wrong with this, mind you.
What if you could connect R, G and B values (join them at the hip) so that when you change one value, the others are forced to change as well? It’s simple 3D geometry:
Don’t be scared by the graph. You have three axes – Red, Green and Blue. Now imagine a point bang in the center, where these three intersect. The values for R, G and B are 0, 0 and 0. This is P1.
Now, imagine moving from P1 to P2. You are moving along the ‘B’ line, careful not to step into R or G territory. After taking 10 steps, you stop at P2. Here, you have moved only in one dimension, and your RGB values are 0, 0 and 10.
Let’s say you start walking upwards, careful to be on the G-B plane, without stepping into Red territory. I haven’t shown it in the image, but you can easily imagine how the values can change to 0, 5, 10, for example. Here, you are moving in two dimensions, and this changes two values at the same time.
Now imagine moving to P3, where you take three steps to the negative side of red, eleven steps to the positive side of blue, and nine steps to the positive side of green. You are moving in three dimensions. Here’s the beauty: You are only moving once, and yet all three values will change.
Look at the power you have:
- If you move along one axis, you only change one value.
- If you move along a plane, you can change two values while keeping the third at bay.
- If you move all over the place, you can change all three values.
By only moving once. Just one trip from hand to mouth. One big juicy bite. Three times as fast as a 1D LUT (well, sort of). Who wouldn’t want a 3D LUT?
In our real-world use, colors are broken down into either:
Luckily, both are in threes.
A 3D LUT is a three-dimensional matrix that gives you the license to move once, yet control one, two or three of the primaries in one sweep.
The mathematical juggling to achieve this feat isn’t that easy or simple to understand, but the execution is as simple as punching the root function on your calculator.
If you want to convert a color space from Rec. 709 to sRGB, just create a LUT and pass your image through it (imagine a filter paper of various colors that you look through to change the color of the world). Imagine your file, the one you recorded on camera, flowing through many pipes to different places. Each pipe has a filter that changes the colors:
E.g., camera shoots Rec. 709.
- Pipe to application – Application LUT (many applications allow you to choose the color space in which you’re working). If you’re working in ACES, the application throws up a Rec. 709 to ACES LUT.
- Pipe to Rec. 709 broadcast monitor via HD-SDI – either your I/O card or the monitor has circuitry that throws up a LUT according to what you’ve chosen in the menu. Why would you want a LUT from Rec. 709 to Rec. 709? Broadcast color is divided as Y’CbCr, so you could shoot in 4:4:4 or 4:2:0 and go to 4:2:2. Color Space is not the only thing that changes color.
- Pipe to sRGB computer screen – either the GPU (most likely) or the monitor throws up a LUT to convert Rec. 709 to sRGB.
All this happens in real time the moment you hit play on your NLE or application.
Are LUTs perfect?
No, they’re not. To achieve speed, they must sacrifice accuracy. E.g., a 10-bit image has 1024 values per channel. R x G x B = 1024 x 1024 x 1024 = a billion colors. For all practical purposes, a 3D LUT cannot be one billion pieces big, or it will defeat the purpose.
Instead, what LUT generators do is define the size of the LUT to a number that achieves good approximation for practical purposes. A common number is 17 points, instead of 1024. 17 x 17 x 17 = 4,913. Isn’t this way low? Actually, no, because the human eye isn’t that perfect. The 3D LUT only calculates these points, and the rest are interpolated (also calculated, but in a ‘broad mathematical sweep’ sort of way).
There is a lot of discussion about whether LUTs are good for critical color grading work. Some people think they are a travesty, while others welcome them. One place where LUTs are definitely valuable is in monitor calibration and viewing, quick image processing on set and computer graphics applications.
When you’re choosing between a 1D LUT and a 3D LUT, go for the option that makes your life easier. Both are compromises. Sad, but true. If they were perfect, they would too large and too slow to be useful for our crazy budgets.
This is how a Look-up table works. For further reading, I highly recommend this article from Light Illusion.