gmic adjust_color desaturation

hello hello.
I’m trying to use adjust_color 0,0,0,0,-50 to desaturate an image but when i compare to the regular gimp desaturate it’s different (lighter)
I’m surprised and wondering why …

G’MIC command adjust_colors changes the saturation using the HSV colorspace.
I don’t know how GIMP does its desaturation, maybe it’s using another colorspace ? (HSI or HSL).

nuke is approx the same as gimp. it says “luminance math : rec709” .
the thing is i need to replicate that on gmic. how could i approach that ?
thanks in advance

Here’s my attempt with Krita. The Middle is GIMP, and the right is Krita.

Not sure if this is good enough for you. Perhaps, GIMP uses the LCH model. I have done this on Krita with document using LAB color space.

1 Like

i tried that. it’s seems closer to gimp effectively.
gmic original.png rgb2hsl split c mul[1] .5 append c hsl2rgb -o ima_hsl.png

Another solution:
I’ve just tried to fit a linear function of R,G,B, such as: f_R(R,G,B) = a\;R + b\;G + c\;B + d, for each R,G and B channels, from the before/after examples you provided (using a least-square approach).
The result is not exactly the same (meaning the actual operator that GIMP applies is not linear), but this gets close anyway.
So, maybe:

$ gmic inputRGB.jpg  +fill. "[0.784929037*R+0.15219751*G+0.0571505912*B-1.20033693,0.329221278*R+0.552827418*G+0.111278839*B-5.04217005,0.307801843*R+0.209704787*G+0.468937188*B+0.554265559]" cut. 0,255

could be good enough for you?

I’ve also tried to fit quadratic functions, but the reconstruction error is not reduced, and there are 3 more coefficients.


For curious people, this is what I wrote to estimate the coefficients:

foo :
  $HOME/Desktop/pouet.jpeg
  rows. 0,779 s x,3 rm.

  repeat 3
    +channels[1] $> y.
    +r[0] 1,{0,wh},1,3,-1 permute. cyzx 1,100%,1,1,1 a[-2,-1] x
    +solve.. . a$>,b$>,c$>,d$>={^} rm[-3--1]
  done
  +f[0] "[
    $a0*R + $b0*G + $c0*B + $d0,
    $a1*R + $b1*G + $c1*B + $d1,
    $a2*R + $b2*G + $c2*B + $d2
  ]"
  e $a0,$b0,$c0,$d0
  e $a1,$b1,$c1,$d1
  e $a2,$b2,$c2,$d2

Possibly done in YCbCr? Something like:
gmic image.jpg rgb2ycbcr sh 1,2 sub. 128 mul. 0.5 add. 128 rm. ycbcr2rgb

You might get some clues by checking what full desaturation does… if you get luma then that’s probably it.

@Jehan Could you clear this up.

Which version are you using? Details can be found here:

https://docs.gimp.org/2.10/en/gimp-filter-desaturate.html

@afre It doesn’t look they are talking about this tool you link since it’s about converting to shades of gray (which is obviously not what people are doing here).

@luluxXX Is the procedure you do in GIMP the Color > Satuation… tool, then setting “Scale” to 0.5? If so, the tool has an “Interpolation Color Space” where you can set “Native”, “CIE Lab/Lch” and “CIE Yuv”. Does’nt it answer the question since @David_Tschumperle says their own command is done in HSV colorspace?

i think i have the response to my question. i didn’t suspect there were so many ways to do it. up to me to find the better solution in my case now. thanks !
(now it would be interesting to be able to pick up the color space in the plugin for sure)

1 Like

I took this at face value. @luluxXX Could you confirm the tool you used? Was it Color > Saturation? If so, the code would be here:

Seem like GIMP use CMYKA model for desaturation, which is weird, but works.