gmic adjust_color desaturation

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