Page 1 of 1

Colorspace When to convert?

Posted: 2017-10-26T10:08:29-07:00
by TedBaker
I am struggling with a few concepts around colorspace, and profiles etc.

I have implemented a transformations that relies on a linear RGB input. (An inversion of a negative film scan)

The output from this transformation is to be further processed by other tools, ideally Rawtherapee.

Rawtherapee internal working space is linear RGB, and supposed to use ProPhoto. I expect to use Rawtherapee to output sRGB files.

My question is should my transformation be converted from RGB to sRGB, If It's assumed that the my output is to further processed in linear RGB?

i.e. is the converion from RGB to sRGB back to RGB and finally back to sRGB lossless?

Re: Colorspace When to convert?

Posted: 2017-10-26T10:16:59-07:00
by fmw42
It would not be lossless, if the image is jpg. Each read and write in ImageMagick will produce some losses due the lossy jpg compression. Other formats such as PNG or TIFF (not JPG compress) should have no loss.

If you want to be exact, perhaps try a linear RGB profile, rather than just -colorspace RGB. In particular, I do not think IM has a conversion to ProPhoto colorspace (https://en.wikipedia.org/wiki/ProPhoto_RGB_color_space). But if there is a Prophoto profile, you could/should use that.

Also note that SRGB and RGB were swapped in older versions of ImageMagick. So please always provide your IM version and platform when asking questions on this forum.

Re: Colorspace When to convert?

Posted: 2017-10-26T13:39:06-07:00
by TedBaker
fmw42 wrote: 2017-10-26T10:16:59-07:00 Other formats such as PNG or TIFF (not JPG compress) should have no loss.
Where could I find a summary of the logic to convert

Linear RGB --> sRGB and
sRGB -> linear RGB

?

Re: Colorspace When to convert?

Posted: 2017-10-26T13:49:58-07:00
by fmw42
Most of the color conversions are in gem.c. But I do not see RGB to sRGB there. So one of the developers or other software knowledgeable people would have to answer that.

But see https://en.wikipedia.org/wiki/SRGB

Re: Colorspace When to convert?

Posted: 2017-10-26T20:34:02-07:00
by snibgo
For a summary of RGB<=>sRGB, see https://en.wikipedia.org/wiki/SRGB#The_ ... amma.22.29 .

Converting between RGB and sRGB is lossless, except that arithmetical precision isn't infinite, so expect an error of about 0.5*2^-16 in Q16 non-HDRI, etc. The code is in colorspace.c and pixel.c.

ProPhoto profiles are available. ProPhoto has a larger gamut than sRGB, so conversion from ProPhoto to sRGB may be lossy, depending on the "-intent" mode of the profile conversion.

As Fred says, saving to JPEG is lossy. Don't use JPEG as an intermediate format.

Re: Colorspace When to convert?

Posted: 2017-10-27T10:52:10-07:00
by TedBaker
Thanks,

Am I correct in my understanding that converting wider gammut colorspace like ProPhoto --> sRGB is losefull?

i.e. Profoto --> sRGB --> Profoto will result in some clipping if the original colours are "wider" than what can be translated into sRGB space.

Re: Colorspace When to convert?

Posted: 2017-10-27T11:17:34-07:00
by snibgo
It depends on the "-intent" setting. I suppose "-intent relative" would give lossless ProPhoto => sRGB => ProPhoto, provided the profiles support that mode, but I haven't checked.