RGB or sRGB expected input when -rgb2xxx invoked

When invoking the various colorspace conversion methods -rgb2xxx, should one first run -srgb2rgb?
That is, should this be run:

gmic myImage.jpg -srgb2rgb -rgb2lab

instead of:

gmic myImage.jpg -rgb2lab

Thanks!

For Lab, yes you should convert sRGB to RGB first, as the transform expect linear RGB as input.
For other colorspaces, I’m not really sure. I’ve implemented the ā€˜classical’ formulas you can see everywhere,
and there often a lack of information about the fact the RGB they use are sRGB or linear RGB.
I’d be interested by a clear answer about that to be honest :slight_smile:

Technically speaking, there is nothing like ā€œlinear RGBā€, since RGB is not an unique representation… what CImg::srgb2rgb() does is to convert ā€œstandardā€ sRGB to ā€œlinearā€ sRGB.

Indeed, in the conversion from sRGB to XYZ (which is the first step for converting to Lab), one needs to use linearized sRGB values.

In the case of the conversion to HSV, the gamma encoding of the input RGB values is, as far as I know, not specified. HSV is actually a color representation and not a colorspace, and as such the H, S and V values depend on the colorspace and gamma encoding of the input RGB triplets. The same is true for the HSL and HSI representations.
However, I’m pretty sure that a conversion from sRGB to HSL, HSV or HSI yields different H and S values depending if the input sRGB values are linear or gamma-encoded. In fact, those representations belong to a pre-colormanagement era, and in my opinion the only meaningful and unique polar representation to be used in modern color processing is LCh (i.e. Lab in polar coordinates).

The specifications are more clear in the case of YCbCr (and Y’CbCr): Y’CbCr must be derived from gamma-encoded RGB values, while YCbCr from linear RGB (as far as I understood).

Y’UV definitely requires gamma-encoded values (Wikipedia only discusses Y’UV, and I could not find any explicit mention of YUV).

For RGB <-> CMY(K) I have honestly no idea yet.

My 2cts :wink:

1 Like

Thanks, Doctors, for your responses. I was using -srgb2rgb as a
preliminary step in my Gmic flows, given earlier discussion on this site
regarding the ā€œlinearā€ input expectations of many Gmic operations, but
then while reading some of the Gmic docs I saw several examples of color
conversion operating directly on input jpg’s…

Thanks again!