How do I access my compressed CLUTs in G'MIC?

As you may or may not know, G’MIC has a module that handles LUTs (multiple in fact) and offers a broad selection of LUTs, organized into an array of LUT packs through the color preset module as well as the simulate film module.
All of these LUTs seemingly live together in a compressed file. Here’s some information on the process behind it: CLUT compression.
I was intrigued by the idea of using that compression for other LUT files that I downloaded from the internet, so I went ahead and did just that, compressed a few hundred files into my own gmz archive and imported it into Darktable where it works as expected.
The G’MIC GUI itself however is a different story. G’MIC obviously understands the format but I can’t find a module, button, option or whatever to load my own .gmz file, which leads me back to my initial question: How do I use my compressed CLUTs in G’MIC? Is there a way to add metadata or rename the CLUTs inside an archive? Maybe even a more sophisticated management tool for CLUTs that works with the gmz format?

Currently in G’MIC-Qt, there is indeed no way to manage other set of CLUT in .gmz than the one by default (gmic/gmic_cluts.gmz at master · dtschump/gmic · GitHub).
I was not even aware that you could import a .gmz CLUT file into Darktable.

In the G’MIC-Qt plug-in, there is a filter that can apply CLUTs stored as .cube or .png files, because that’s the most common file formats used to store CLUTs.

I was wondering if you’d agree to share your CLUTs ? If so, we could add those in the default CLUT pack distributed with G’MIC and make them appear in the Color Preset filter under a new Category (you choose the name).

If I remember correctly, that functionality directly calls G’MIC itself but is completely transparent. It does not show any metadata aside from the name and is a bit clunky to use but it does work. Here’s a blog post that talks about the module, complete with instructions on how to compress .cube and haldclut files through G’MIC.

Unfortunately these CLUTs aren’t mine, they are somebody else’s work and aren’t licensed in a way to be shared freely.
It wouldn’t really solve the problem anyway, because there are thousands of CLUTs in thousands of packs and bundles all over the internet with all sorts of licensing attached and people who collect these by the thousands might be intrigued by the possibility of significantly reducing the file size (even if the compression takes a few weeks of processor time) and then have an easy way to use them in G’MIC. Since this isn’t currently possible, I’d like to propose this as a change to either the Color Preset filter or the Apply External CLUT filter or as an entirely new module, whatever you prefer.

I see.
I’ll think about creating a filter that allow a user to specify its own set of CLUTs in the form of a .gmz file.

1 Like

That would be awesome, thanks in advance.

Here is a first attempt: New filter “Colors / Apply From CLUT Set”.
You basically specify a .gmz file and an index, and the corresponding CLUT is applied on the selected images.

(should be available after a filter refresh, for G’MIC 3.1.0+).
Please tell me if that is working for you.

Note that there is no way the plug-in can dynamically generate an interface that depends on the input .gmz file (so I cannot propose a combobox with the list of CLUTs in the set for instance).

1 Like

On the topic of G’MIC cluts, I would like to “fill in the blanks” of a sparse CLUT. The sparse CLUT might be generated from a pair of two images, a “from” image and a “to” image, so the CLUT would transform one image to the other.

I haven’t investigated properly, but I think G’MIC contains the functionality to do this. Ideally, I would like a G’MIC CLI command that takes two images, and make a completed CLUT.

For example, a CLUT could then be used as an approximate but very fast conversion from sRGB to Munsell HVC, or HVC to sRGB.

(I have developed a method to populate sparse CLUTs with ImageMagick, but it is massively slow.)

Any pointers are welcome.

It’s not working for me right now but that’s not your fault. My distro’s repository still lists 3.0.2 as the current version, so I’ll have to figure that out.

Would it be possible to generate a better interface if the gmz files were loaded in a more static manner? I’m thinking of having a set of predefined files (like the established gmic_cluts.gmz but specified by the user) that are scanned at startup instead of runtime.

I haven’t investigated either but have you looked at the CLUT from After – Before Layers filter in G’MIC?

We have a filter in G’MIC-Qt specifically dedicated to this task : from two input layers, it reconstructs a smooth CLUT that transforms the second one (bottom layer) into the first one (top layer).
It fills the gaps (colors that do not exist in the given image) with a multiscale diffusion algorithm (which is reasonnably fast).

The filter is named Colors / CLUT From After / Before Layers.

To invoke this filter from the command line, you can do this:

$ gmic modified.jpg original.jpg fx_clut_from_ab 0,4,"","",50 rm. o haldclut.png

(the command looks a bit esoteric, but that’s because we invoke the filter itself, there are no G’MIC “atomic” commands that does the job :slight_smile: ).

1 Like

Maybe a few additional info:

(for the Before/After application, see last section of paper).

  • The filter is able to output the estimated CLUT as an haldclut or directly as a .cube file.

  • There is a Influence of Color Samples parameters that set how much the known color transformations must “expand” in the RGB space when interpolating the sparse data.
    If this parameter is low, then RGB points that are far from any known transformation will have a tendency to keep a transformation that is close to the identity.

Yes, it is always possible to design your own filter with all the necessary data.
What could be interesting is even to implement a G’MIC command that automatically generates this filter, from the .gmz file.
Maybe I’ll give a try later today.

Excellent, many thanks, @David_Tschumperle.

I have updated G’MIC to 3.1.0 for GIMP, and CLI (on Windows 8.1). It seems to work fine in GIMP.

fx_clut_from_ab seems to be documented at G’MIC CLUT from After Before Layers node — Natron 2.5.0 documentation

But I have problems with the output CLUT resolution. “4” and “9” work, but “16” doesn’t.

f:\web\im>%gmic% toes.png t.png fx_clut_from_ab 0,16,"","",50 rm. o haldclut.png

[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input file 'toes.png' at position 0 (1 image 267x233x1x3).
[gmic]-1./ Input file 't.png' at position 1 (1 image 267x233x1x3).
[gmic] *** Error in ./fx_clut_from_ab/*repeat/*local/*local/*if/ *** Command 're
size': Invalid argument '0,0,0,3,3'.
[gmic] Command 'resize' has the following description:

  resize (+):
:
:
etc

I tried with larger input image files, 1000x800 pixels, but that doesn’t help.

The parameter for the output CLUT resolution is the index of the choice for the filter, so:

  • 0 → 16
  • 1 → 25
  • 2 → 36
  • 3 → 49
  • 4 → 64
  • 5 → 81
  • 6 → 100
  • 7 → 121
  • 8 → 144
  • 9 → 169
  • 10 → 225
  • 11 → 256

(it’s not directly the resolution you want!).

1 Like

Ah, yes, that explains it. Many thanks, David.

1 Like

I was finally able to test the new filter and while it works, it clearly suffers from not being able to change the UI at runtime. Starting with index 0 is fine with me but the full number of CLUTs in the file is subsequently off by 1, which should be an easy fix.
Nevertheless, it’s perfectly functional and certainly a valuable addition. Thank you very much for writing it, on a Sunday no less.

A small update today, with more controls to adjust colors after the CLUT application:

1 Like

I appreciate the controls but the preview is broken now if there is a space in the file path. Clicking OK or Apply still applies the filter though.

Thanks for reporting, it’s fixed now.