Jump to content
You must now use your email address to sign in [click for more info] ×

Small Look-Up Table(s)


AdamStanislav

Recommended Posts

I understand that Affinity Photo can use LUTs. While I do not have Affinity Photo (I would have gotten it recently had I not been too busy working on my fonts to notice it was 50% off, but I missed that and now have to wait for the next time they discount it like that), I do use LUTs in my video work.

Indeed, not only do I use them, I actively create them. And I go against the grain by making them small. For some reason many people seem to believe that the larger a LUT the better. That may be true occasionally, but there are myriads of color filters that can be fit into the smallest LUT possible (which is eight data lines in case of 3D LUTs), and making them bigger is actually a bad idea.

I actually created an OFX plug-in (they are used in video editing) for color grading which makes sure all it does can be fit into such a small LUT. The original plug-in is kind of small (I have learned a lot since creating it), and in 2019 I wrote a library of routines (seen here, though with no documentation yet), to rewrite my plug-in with. But then I got very sick (no, not with Covid), spent most of 2020 in medical care, after which I started working on my fonts, so my OFX plug-in has to wait.

But I still use the original plug-in, have created a wide variety of LUTs, all small of course. Just this morning, I have been playing with it, and came up with an interesting (or so I think) LUT I named tehla (which means brick in Slovak) because it sort of strengthens brick like colors in an image, making it warmer, especially in photos and videos of human faces.

So I thought I’d share the .cube version of it with anyone here who might want to play with it in their Affinity Photo (I hope .cube is the right format for it).

I have never uploaded any LUT here, so I hope I have done it correctly for you to get it from here. If not, I will just copy and paste it in the next message. After all, it is a very small LUT.

Tehla.cube

Link to comment
Share on other sites

And just for comparison, here is the same image with Vzduch.cube, which is essentially the opposite (or perhaps the complement) of Tehla.cube:

Wine-Vzduch.thumb.png.9be50e983a311ce93121e302c3f676a8.png

Both work on the principle of strengthening certain colors, while leaving the rest of the colors untouched. Tehla strengthens the colors in the neighborhood of orange, which Vzduch (meaning Air in Slovak) strengthens the colors in the neighborhood of azure.

Vzduch.cube

Link to comment
Share on other sites

10 hours ago, Smee Again said:

Missed this earlier because I was busy. Between some mapping work, preparing a talk for Thursday, and trying to psych myself up for chemotherapy tomorrow -- I sorta blew through things.

Look good, so I downloaded them. When I get back tomorrow evening or Tuesday I'll give them a look. Thanks

Many years ago I was faced with a year of chemotherapy.  Early on it occurred to me that if I was feeling that foul, just THINK what those stray cancer cells were feeling!  It made each trip for another dose less daunting.  They lost.  I won.   So chin up!  And very best wishes to you!!


24" iMAC Apple M1 chip, 8-core CPU, 8-core GPU, 16 GB unified memory, 1 TB SSD storage, Ventura 13.6.  Photo, Publisher, Designer 1.10.5, and 2.3.
MacBook Pro 13" 2020, Apple M1 chip, 16GB unified memory, 256GB  SSD storage
,  Ventura 13.6.   Publisher, Photo, Designer 1.10.5, and 2.1.1.  
 iPad Pro 12.9 2020 (4th Gen. IOS 16.6.1); Apple pencil.  
Wired and bluetooth mice and keyboards.9_9

Link to comment
Share on other sites

Don't know if it was smart or not, but first Oncology doctor was quite difficult to deal with, and treatments were not consistent. Transferred to UAMS and they got right on it. They give more info about what is going on. I finally know what stage. I get to see my blood work. They (so far) don't tell me "do not come in" and then fuss at me when I obey their instructions.

Back to fun stuff . . . Tried the luts late last evening: really good work. Thanks for sharing!

Link to comment
Share on other sites

One of the things that took me a long time to figure out (which is quite embarrassing given that I am a psychologist, so it should have been obvious) was how they do it in the movies when they reduce all colors to just two (usually referred to as maroon and teal), when our vision is based on three colors, red, green and blue. The effect keeps the red and the green, I thought, but what happens to the blue??? Like this,

Wine-Dichromatic.thumb.png.22fb49d81e2a72c6bed36a3b9676c1e7.png

When I finally figured it out, it was such a duh moment! There is no green in the image! It is a simple matrix calculation:

    1 0 0 0
    0.2627 0.678 0.0593 0
    0.2627 0.678 0.0593 0

The three lines represent the three channels (r, g, b) and the four columns in each line show the what you multiply red, green, blue, and alpha with and then add it up. So, the first line means red stays red (1*red + 0*green + 0*blue + 0*alpha), and the other two are converted to gray. It is our brains that delude us into thinking there is green because all they see is red and not red, so they tell us the not red is the opposite of red, which technically is cyan but somehow in this illusion we perceive it as teal. So darn obvious!

I decided to call the effect dichromatic and am including the LUT version of the above matrix.

And I then took it a step further. What if we kept two of the three color channels (any two) and change the third one to gray. Or even rotated the hue in the two non-gray channels, we could get an infinite number of possible results. Like in this example,

Wine-Anachromatic.thumb.png.3b4af73c4442f10cb9cd6c8e6927c71e.png

Again, all it takes is a simple matrix. In this case it looks like this:

    0.2627 0.678 0.0593 0
    -0.1220276122 0.9079384044 0.2140892078 0
    -0.6941229391 0.6279308965 1.066192043 0

So, the red channel is turned gray in this example, and the other two are rotated, each by a different angle. I call this method anachromatic.
 

dichromatic.cube anachromatic.cube

Link to comment
Share on other sites

Or if we want something wild, also back in 2018, I tried to convert colors to what a vampire might see. I called the result Vampyrectomy (which literally means surgically cutting out the vampire disease, which, I guess, is the opposite of what I was trying to create):

Wine-Vampyrectomy.thumb.png.a9257f8058c6b631be90231356b24450.png

Vampyrectomy.cube

Link to comment
Share on other sites

Once more, very good work. I need to look into this.

One thing Affinity photo is missing is a "layer fill slider" that would help to take advantage of the 8 special blend modes. If they ever add that feature, I believe it would improve what the end user could achieve with the luts you are able to create.

I really like them, and they are fast even on my old machine -- a custom rig (gaming PC AMD Quadcore) I built in 2009 when my alienware bit the dust. Oh it will still outperform most "off the shelf" towers 12 years later, but it is starting to show its age with some of the newer software. Some other luts I've used take a few seconds to load so I'll ascribe that to the age of the computer.

Link to comment
Share on other sites

11 hours ago, Smee Again said:

Some other luts I've used take a few seconds to load so I'll ascribe that to the age of the computer.

It might actually be the LUTs. Since I developed a software library to create and apply LUTs, I can tell how easy it is (for the computer) to apply a simple small LUT and how complicated it is to apply larger LUTs.

The problem with many LUTs is that people who create them start by producing a certain effect and when they like the result then and only then do they export the result to a LUT, often not quite understanding the math behind a LUT, and they think the larger the better. Even Affinity Photo, sadly, seems to have a slider it calls Quality, which implies that larger LUTs are better. I said seems to because I do not have it, so I am just going by what I saw in the official tutorials.

My approach is the opposite. I start with the LUT that is like a cube with eight vertices, then I move the vertices to achieve the desired effect. It is very rare that I need a more complex LUT than the basic cube. I developed an entire working model, which I really should write the docs for, but essentially there are eight vertices: black, white, red, green, blue, cyan, magenta, and yellow. Of them I refer to the black and white vertices as the svit (which is hard to translate from my language but essentially it has to do with intensity of the light). If you adjust those two vertices, you can change the overall brightness and contrast of the image with out affecting the colors. The other six vertices I refer to as farba (which literally means color in Slovak). Adjusting any of those will affect the colors but has little effect on the overall brightness and contrast of the image. And I just love playing with it. After all, I’m 71, and we are supposed to be like children after a certain age. 👴

The math behind the LUT is a simple 3D interpolation, which is quite simple with a cube. The larger LUTs effectively cut the cube into many smaller cubes and the computer has to figure out for every single pixel which of the small cubes to apply to that particular cube. A photo can consist of millions of pixels, so it takes extra time to apply a larger LUT even in a very fast computer.

Now imagine a video which has 24-60 frames per second, each frame with a million or more pixels, so to apply a slow big LUT to just a ten-minute video takes a very long time. And since I make videos, I needed to speed the process up and that is why I came up with the idea of the LUT being the starting point of color grading rather than just an afterthought.

Link to comment
Share on other sites

Here is an example of what I am talking about, one of my favorite LUTs to produce a dramatic look:

Wine-CP.thumb.png.d9e37894c75c4fb5f19491f7d732f956.png

You can examine the LUT, cp.cube in a plain text editor. Lines 5-12 contain the actual LUT, in the order of black, red, green, yellow, blue, magenta, cyan, white. That order is specified by the .cube specs, not by me. Each line contains three numbers, for the red, green and blue channels (in that order).

You will see that black has values slightly below zero and white slightly above one, which increases the overall contrast of the image. Red, green, and blue have small values, which makes them darker. Cyan, magenta, and yellow have 0.7549019605 where there would be a 0 by default. That makes them lighter (this may seem counter-intuitive, but to make red, green and blue less pronounced you bring them down from 1 to a smaller value, while to make cyan, magenta, and yellow less pronounced you bring them up from 0 to a larger value).

And the result is quite dramatic, I’d say.

cp.cube

Link to comment
Share on other sites

@AdamStanislav "After all, I’m 71, and we are supposed to be like children after a certain age. 👴"   That makes you a mere youth, or at least just out of the "wet behind the ears" stage!  To quote the poet Robert Frost, hopefully you will have "miles to go before I sleep."  In the meantime, thank you so much for these elegant LUTs!


24" iMAC Apple M1 chip, 8-core CPU, 8-core GPU, 16 GB unified memory, 1 TB SSD storage, Ventura 13.6.  Photo, Publisher, Designer 1.10.5, and 2.3.
MacBook Pro 13" 2020, Apple M1 chip, 16GB unified memory, 256GB  SSD storage
,  Ventura 13.6.   Publisher, Photo, Designer 1.10.5, and 2.1.1.  
 iPad Pro 12.9 2020 (4th Gen. IOS 16.6.1); Apple pencil.  
Wired and bluetooth mice and keyboards.9_9

Link to comment
Share on other sites

45 minutes ago, jmwellborn said:

In the meantime, thank you so much for these elegant LUTs!

Well, I’m actually trying to let everyone know how to make your own LUTs. For example,

Wine-Rust.thumb.png.825651e630f96b15f7da85f2d200e64a.png

If you look at Rust.cube in a plain text editor, you will see the black vertex (line 5) is 0 0 0, which is the default black. And the white vertex (line 12) is 1 1 1, the default white. That tells us the brightness and the contrast remain the same, no matter what the rest of the lines are.

And indeed, all the other lines are 0.5803921819 0.270588249 0.1411764771, which is roughly a rust color. That tells us that every pixel, regardless of its original color, will be set to that rust color, but will keep its original brightness.

And we know that if we keep black and white at its default values and replace all the rest with identical lines, we can have the same effect as this for any color we want. It could be blue, it could be sepia, it could be anything. And we can do that in a plain text editor. We need to keep the header (lines 1-4) as is, except we can change the text between the quotation marks in the first line. Line 14 is just a comment which we can discard. And now you can create any number of effects.

Rust.cube

Link to comment
Share on other sites

Well, I’ve written a few new routines to my library (have not uploaded them yet, though), which allowed me to create an entire series of LUTs derived from one base LUT. And today I tried to see what would happen if I changed the farba (again, that is red, green, blue, cyan, magenta, yellow vertices) in a way that is normally used to increase the contrast, but kept the svit (black, white) at the defaults. The result was kind of a dreamy look. I wish I could show you some of the pictures I tested it on, alas I do not have the right to post them, so I will show it again on the stock image:

Wine_Liebestraum.thumb.png.75fa3799368d21030306b85c814ffcd9.png

I spent several hours staring at the various images with this LUT applied, while listening to Liszt’s Liebestraum (because the images looked dreamy) over and over, trying to figure out the nature of the effect, which seemed very familiar but I could not think of the name. And then it hit me. The LUT was acting like a diffuser, making it look like the pictures were taken with a much softer light than they actually were. This surprised me because I was always assuming the only way to achieve such an effect would be softening the image by averaging neighboring pixels, not by manipulating each pixel on its own, let alone with such a simple LUT!

More importantly, however, the program I wrote applies filters of the 48 colors from primary to quintary (I know Wikipedia calls it quinary, but as a graduate of the last department of the last Roman university that still had all of its lectures in Latin, I cannot stand that word but am willing to compromise on quintary).

It applies the filters by interpolating the base LUT using two sets of interpolation values, one that I called F for filter, the other X for extreme filter. And what does it interpolate with? Well, three separate LUTs. One is the default Identity LUT (i.e., one that does not change anything) which I marked I, the other is LUT of just zeros in everything in the farba department, which I marked O and one is what I call the Home LUT which I marked H.

And so we have 6 times 48 = 288 LUTs in addition to the base LUT. Enjoy!

 

Liebestraum.zip

Link to comment
Share on other sites

Oh, I always forget to mention that some of these LUTs, especially in the Liebestraum collection are very strong (especially the dark blue ones), but you can always make them look good by using the strength slider (I believe Affinity Photo calls it the lowering of the opacity of the adjustment layer).

By the way I see my pet peeve in Affinity help. It claims a LUT works a matrix. Not true! The word matrix has a very specific meaning in mathematics, as does a look-up table. And they are not the same. Just because both have columns and rows does not make them even close to being the same. Some effects are indeed produced by a matrix, but they are a different thing. A matrix represents a linear function or a set of linear functions. Generally, they are used to solve sets of linear equations with multiple variables. A look-up table represents an interpolation or a set of interpolations. When I was in high school back in the Sixties, there were no personal computers, so we had entire printed and bound books of look-up tables for the trigonometric functions (and other LUT books for logarithms and such). A sine, cosine, tangent, etc, none of those are linear functions. Neither are logarithms. As such, they cannot be defined by a matrix. But they sure can be approximated very closely by those look-up tables.

So come on, Serif! You have the famous University of Nottingham nearby, consult with its mathematicians before making such wild claims in your help documentation.

Link to comment
Share on other sites

11 hours ago, AdamStanislav said:

Oh, I always forget to mention that some of these LUTs, especially in the Liebestraum collection are very strong (especially the dark blue ones), but you can always make them look good by using the strength slider (I believe Affinity Photo calls it the lowering of the opacity of the adjustment layer).

I tend to use the opacity (because of the lack of a "Layer Fill" slider, but also vary them by use of different blend modes as well. A third way would by by "blend-if". Don't like the weird way blend-if is adjusted in Affinity, but it does work most of the time. It sometimes seems that the software can't remember which is the source layer and which is the underlying layer. Occasionally, both adjustments appear to be applying to only the source layer -- which doesn't really help.

Link to comment
Share on other sites

Just having a little more fun today to make an example how a lot of math can be squeezed into a simple LUT:

Wine-ChromaFun.thumb.png.2b0f1a7fb4bdf3cbb8b717f423872a5a.png

So what is the math I mentioned?

Well, first we take the red, green, and blue values of each pixel. We then convert them from the RGB color space to the YCC color space using the current Rec. 2020 method for that (YCC was originally created for color TV, so they could transfer the old monochrome signal Y to those who only had a B&W TV set, while adding the two C channels that can be used to convert that B&W signal to color). After that conversion, we rotate the C and C (generally called chroma) by the angle of 17 degrees. We then interpolate the result with an unrotated chroma, so we effectively end up with only 11% of the 17 degrees (in other words, the chroma is now rotated by about 1.78 degrees). After that we multiply the chroma by 0.7231, which cuts down the saturation to 72.31% of its original. We then stretch the Y channel to the span from the black of -0.05 (instead of the original 0) to the white of 1.1 (instead of the original 1). This increases the contrast by 15% and the brightness by 10%. Then we convert everything back from the Rec 2020 YCC color model to the RGB color model.

And instead of doing all that math for every single pixel, we now have a simple LUT which is much easier to apply to each pixel than all that complicated math.

ChromaFun.cube

Link to comment
Share on other sites

Here is another one. Suppose we turn all colors in an image 90 degrees, and only after that do we apply the 48 color filters I have been playing with all this time. If we then load, say, the emerald filter, will it let the emerald colors through, or the colors that were close to the emerald in the original picture but have since been modified by the 90-degree-LUT?

Before you look at the picture, here is a hint: The filter is applied to the original 90-degree LUT, not to the image produced by that LUT. It is sort of like a painter holding a palette on which he normally has eight inks, black, white, red, green, blue, cyan, magenta, yellow. He uses his brush to mix any desired color from the eight inks. But today someone has swapped the six inks other than black and white with some other inks, but he does not notice it (maybe he is a computer or some kind of robot that just does what he is programmed to do). So he keeps mixing his colors as usual, in the same proportion of the eight inks as he always does for this painting.

And that is what happens when we apply a filter to an existing LUT, which represents his palette, albeit modified.

OK, so here is the emerald filter applied not to the original image but to the palette (LUT) that had all its colors rotated by 90 degrees:

Wine_90Degrees-Emerald.thumb.png.37c5c102606f006caa0d563c9741c8f1.png

90Degrees.zip

Link to comment
Share on other sites

Last night I was thinking I should try something new: Use my 48-color filter technique in the opposite way, i.e., instead of interpolating an existing LUT against one of the default LUTs, maybe I should interpolate it against another LUT, or perhaps interpolate one of the defaults against a LUT (which is not the same as interpolating a LUT against a default, kind of like 2-1 is not the same as 1-2).

I added that ability to my software, then tried various combinations all day long. While doing that I found one of my LUTs from 2019, similar to the dichromatic LUT I already showed here, but this one has increased contrast and even some saturation to deal with with the loss of both in the original dichromatic due to it being an optical illusion. The one I found I had called Dichromega:

Wine-Dichromega.thumb.png.099937a77e097b44c42a7af76bc00009.png

I then interpolated it against the default but was not happy with the result, so I tried the aforementioned opposite (interpolated the default against it) and that looked better. I only did it with the six primary and secondary colors, then converted it and the six interpolations into the .cube format and compressed the result in the enclosed zip file.

Dichromega.zip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.