Colorspace When to convert?

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
TedBaker
Posts: 50
Joined: 2017-10-10T14:14:55-07:00
Authentication code: 1151

Colorspace When to convert?

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Colorspace When to convert?

Post 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.
TedBaker
Posts: 50
Joined: 2017-10-10T14:14:55-07:00
Authentication code: 1151

Re: Colorspace When to convert?

Post 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

?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Colorspace When to convert?

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Colorspace When to convert?

Post 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.
snibgo's IM pages: im.snibgo.com
TedBaker
Posts: 50
Joined: 2017-10-10T14:14:55-07:00
Authentication code: 1151

Re: Colorspace When to convert?

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Colorspace When to convert?

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply