Generate LUT from swatches?

Is there any software out there that can generate a lut from swatches/palette? I imagine the difficulty lies in swatches typically having < 256 colors and luts many thousands, but if it could be achieved it would make it incredibly easy to match the look of your favourite images.

Thanks Iain. So it seems this works by matching a source colour to a target colour - whereby the user must select both. This could work for my purposes, though would be quite time consuming if one had a lot of source colours.

I have thought of how a system might work requiring only a reference image (from which colours will be taken from) and haldclut.

  1. Open reference image
  2. Generate palette (and/or allow users to dropper pick palette from image) of x colours (lets say x = 256, and lets call them ‘reference colours’). Make sure this palette includes the min, max, and average (or median), and only unique rgb values, no repeats. [Alternatively, with no reference image, a user could type in the rgb, lab, hex values etc… of their own reference colours.]
  3. Where RGB values of reference colours = RGB values on haldclut, these values remain unchanged (lets call them ‘unchanged values’). All other values on haldclut will change. How? Some algorithm (I’m no mathematician) blending the 256 reference colours with each other, weighted by how close they are to the unchanged values. eg. Lets say unchanged value i = red, and unchanged value ii = blue. A value 1% removed from i will become 99% red and 1% blue. While a value 50% removed will become 50% red, 50% blue. Of course, this is a simplistic example. In reality, the formula will need to take into consideration not just two, but many of the 256 values. In this way, it would be somewhat similar to the G’mic Colourful Blobs filter, but in Lut form. The ‘unchanged values’ represent the blobs, and all the other values represent the merging of those blobs.

I have no idea the difficulty of implementing such an idea, but thought I’d leave it here in case there is interest.

There is another GMIC filter called ‘CLUT - apply from after-before layers’, which takes two images and approximates the CLUT that would produce the ‘after’ layer from the ‘before’ layer.

This requires the before and after to be the same image, just with a different grade. Good tool, but not what I’m trying to achieve. The before and after have to be different images. One, the look you are trying to match. Two, all colours (as represented by the haldclut).

Hi, I think you want this: Tricubic interpolation - Wikipedia

The images in the before/after CLUT filter could be a 16x16 pixel (256 pixels) images of the colour patches you want to use and how you want them to be changed.

Or even something like this

1 Like

Unfortunately I am too much of a simpleton to know if this is correct or not, but I hope someone else does.

But don’t the before/after images have to be exactly the same in content? So if I was going to generate a 16x16 palette, the colours would have to line up with some generic palette to match to. In other words, green would have to align with green, red with red, white with white, etc… Palette generators don’t do that. I ask these questions of the gmic plugin, as I can’t test it myself.

Gimp today reminded me why I haven’t tried to use it much. First, in PS, I used a 24 patch colour chart converted to linear rec 2020. Then I opened a reference image converted to linear rec 2020, and generated a 256 colour palette. I then replaced the colour of each square in the chart with its closest match from the palette, and saved both as png. Opened both in gimp and converted to linear rec 2020 profile. But when I tried to paste one as layer on top the other, the top layer was completely washed out (it didn’t look that way in its own tab). But it wouldn’t have mattered anyway. The Gmic-Qt plugin isn’t available on mac. I found a github source to download gmic-qt plugin for mac, put it in the gimp folder, re-opened gimp, and it now showed up in filters list, but while clicking it made the icon pop up in dock, nothing actually opened.

So I ditched gimp (I will be able to retry in the not too distant future when I get Linux) and found another way to calculate the difference between the two files (3dlutcreator). I then applied this lut to some test images. The results were ok, in the right direction, but not perfect. So what’s the problem? There are two. 1) The colour chart is limited to 24 squares. 2) Mapping one square from the palette to one square on the colour chart is arbitrary. Whose to say which square it should be matched to? I chose the one that was closest, but it is still a random choice. Sometimes the saturation was increasing, sometimes decreasing, how was I to know whether that particular square should increase or decrease? All I could do was pick the closest. This is why I said above the best system would have the RGB value in palette = the same RGB colour in the haldclut. Leave that one as is, and change the rest. That way it isn’t arbitrary. It’s an exact match. Then the only colours you’d have to change are the ones you don’t have data for (that is, the ones outside the palette/image). That’s the real question here - what to do with the rgb values in haldclut you have no data for? I provided one solution (in idea), which is to blend gradients between rgb values in the palette you do have data for. @agriggio may have provided the maths to that, or may have provided an alternate solution (I’m not sure which). Another alternate solution would be not to blend colours - which would generate new hues not in the original image/palette (eg. if you started with two colours, red and blue, you would now have three, magenta) - but to shift all hue not in palette/image to hues that are. Another solution might be to desaturate all colours not in the palette. It might be that any of the above are viable solutions, pending taste.

So with this idea, matching to a colour chart or grid doesn’t work. It is what happens to the colours outside the chart that is important. The grid colours should just equal the palette colours exactly, unless you know whether it is supposed to saturate/desaturate, lighten/darken, that particular colour on the grid - which is the kind of thing you are highly unlikely to know.

Anyway, I am appreciative of the responses. Just trying to explain the concept of what I’m looking for.

No colors doesn’t have to match. You can map a green to an orange, a black to a yellow, etc…
The only constraint is “spatial” : the color correspondences must be defined at the same pixel locations.

But in your example, this would mean green turns orange, and black turns yellow, right? That’s not what I’m trying to achieve. I want green to remain green. Therefore, the colours in palette would have to align spatially to those in chart/grid.