Palette to clut to application

I’ve quickly tested a simple idea, let me explain it briefly.

Considering one source image I and one reference image R, we want to generate an image J that looks like I but with the colors of R.
What I’ve tried is :

  1. Take all the existing colors in R and put them in a CLUT. We end up with a volumetric image with a few colored points, and black everywhere else (so a lot of black).
  2. Use the G’MIC solidify algorithm (command solidify) on that sparse CLUT, to fill the missing values by interpolation the known colors of R (it uses diffusion PDEs for that task). → Now, we have a full CLUT, with only interpolated colors from R.
  3. Apply that CLUT to the source image I to transfer the colors from R to I.

This is done basically by this code sample:

trcol :
  sp butterfly,dog  # Source and reference images
  64,64,64,4        # Resolution of the 3D CLUT : 64x64x64, with alpha-channel
  f.. "I(#-1,round(I/256*w#-1)) = [ I,255 ]"  # Fill CLUT with known colors of `R`.
  solidify. 75%,1,20  # CLUT completion -> all CLUT entries will get a color.
  +map_clut... .  # Apply that CLUT to the source image

I get something like this, for instance (Butterfly = source, Dog = reference) :

Another example (Pencils = source, Wall = reference) :

And another one (Greece = source, David = reference) :

Of course, if your reference image has a lot of different colors in it, there won’t be a lot of difference between the source image I and the generated image J.

Maybe this could be an idea for a new G’MIC filter in the plug-in, what do you think ?

2 Likes