linear color transfer in gmic ?

it does a lot on my side.thanks

1 Like

@luluxXX Your questions usually help improve G’MIC. Thanks. :+1:

1 Like

All this time, I never realized you could use commands within fills. Other than that, I might use this to improve transfer color [Reduced Colors].

So, here it is : Command transfer_pca is now available in the G’MIC stdlib available after a $ gmic update as usual (assuming you run G’MIC 2.8.0+).
Here is the command help :

 gmic -h transfer_pca

  gmic: GREYC's Magic for Image Computing: command-line interface 
        (https://gmic.eu) 
        Version 2.8.2 (pre-release #200110) 
 
        Copyright (c) 2008-2020, David Tschumperle / GREYC / CNRS. 
        (https://www.greyc.fr)

    transfer_pca:
        [reference_image],_color_channels

      Transfer mean and covariance matrix of specified vector-valued reference image to selected images.
      Argument 'color channels' is the same as with command 'apply_channels'.
      
      Default value: 'color_channels=all'.
      
      Example: [#1]  sample lena,earth +transfer_pca[0] [1]

Good things with the G’MIC version of the pca-transfer implementation:

  • It works for 3D volumetric images.
  • It works for an arbitrary number of channels.
  • It is parallelized.
  • For a color image, you can specify which color channels are considered for the transfer.

So, if I do a similar thing to what is described in the article from Gatys, linked by @luluxXX, I can do it in two steps :

$ gmic sample zelda,earth +transfer_pca[0] [1],ycbcr_y  transfer_pca[-1] [1],ycbcr_cbcr

which gives:

That’s all for tonight.
I’ve used some cool tricks to code this command, so I’m planning to do similar things in command transfer_histogram to make it slightly faster.
After that, I’ll add this new PCA-transfer option to the style transfer algorithm of G’MIC, to see what happens…

Until then, good night, and have a great week-end :slight_smile:

7 Likes

Very nice function, still some flaw (overflow or cutoff!), try

gmic sp portrait2,monalisa +transfer_pca[0] [1],ycbcr_y transfer_pca[-1] [1],ycbcr_cbcr

While your example gives a quite strange result (but a result that can be explained), I don’t see any overflow value in the rendered image.

[2] = '_portrait2':
  size = (800,800,1,3) [7500 Kio of floats].
  data = (128.395,129.372,133.618,136.186,136.186,133.618,133.618,133.618,136.186,133.618,134.105,126.99,(...),104.451,99.8682,99.8682,99.8682,106.592,99.8682,100.175,100.175,100.175,100.175,100.175,96.6649).
  min = 0, max = 221.713, mean = 95.2109, std = 49.4719, coords_min = (403,36,0,1), coords_max = (636,425,0,0).

I expected something like that during computation, typically for the discontinuities! Still an explanation for them could be interesting!

thank you afre.your answers usually help improve myself.

wow.that’s a good surprise at breakfast.will try that asap.thank you so much David.

The commands here are not used within fills. There are evaluated even before the fill command starts, because they are called outside the fill string double quotes, so they are substituted in the fill argument before it starts.

The shadows and gamut clipping should be put under control somehow in there. Luminance details got lost.

The command transfer_pca just transfers the covariance matrix and mean vector from one image to another one.
I guess that it’s not enough by itself to say it transfers colors. Additional commands may be used to fine-tune the result.

@David_Tschumperle, thank you for this filter.

I have the following error:

This happens also with "Transfer Colors [Histogram], not with the other two transfer_colors filters.

@iarga, that is really worrying. Looks like the recently introduced store commands does not work as expected for you, and I plan to use it more and more in the future.
We really have to find what is going on.

May I PM you next week, to make you tests some custom builds of the plug-in ?

Works fine and dandy for me using Krita 4.3 Pre-Alpha and G’MIC 2.8.2.

@David_Tschumperle, yes you may.

The error is in GIMP 2.8

in GIMP 2.10 (samj) it works:

Works for me. I have GIMP 2.10.12. (BTW, I am getting the same preview problem as afre_softlight where the preview is cropped and shifted. What happens depends on the preview space given relative to the images’ dimensions. I think it happens when the top input layer is smaller than the bottom one. Reset zoom usually corrects it.)

When you get the error with GIMP 2.8… How did you install the G’MIC plug-in there ?
Using the installer from the official http://gmic.eu site ? or from another source ?
It’s important to know that the bug appears on the version distributed on the official site, because we can ensure the compilation has been done properly.

I always use the zip, so I used this:

[ ] gmic_gimp2.8_win64.zip 2020-01-09 19:17 33M

OK, I’ll test this on my Windows VM, but not before next monday.

1 Like