question about gamma correction in toolchain pipeline

Gamma correction is one necessary step in raw processing pipeline. It seems that gamma correction is not contained in toolchain pipeline in RawTherapee from the link
https://rawpedia.rawtherapee.com/Toolchain_Pipeline.

However from the link Color Management addon - RawPedia


It mentions that an internal gamma is set by RawTherapee during the conversion from rgb to RGB.
Does it mean that steps from 3 Retinex to 13 Tone response curve work on 12 or 14 bit rgb and
following steps after step 13 work on 8bit RGB after gamma correction?

Welcome to the forum.

So-called gamma correction is done in the display and export color transforms, to the needs of those respective media.

Maybe I use the incorrect term. If gamma correction is defined as wikipedia Gamma correction - Wikipedia, I means gamma encoding in my original post.
One gamma processing is always applied for linear rgb data from imagen sensors. There are several tone curve options in RawTherapee. Some are located before gamma processing and some are after gamma processing. I am try to find out the roles of each tone curve option.

The entire processing chain itself is akin to a fancy gamma correction, as RAW images are linear encodings. The term gamma refers to the particular transform that exists between linear and some curve. In photography, that refers to the brightness of the image and is adjusted by applying a curve to the luminance.

Very roughly:

Gamma shape shown in green.

Beyond the RAW, a specific gamma value for output can be encoded into an output format like JPEG. If the sRGB space is used, that gamma is 2.2. For CRT monitors, 2.2 ends up maximizing the color space.

Your display monitor can also have gamma correction applied by the operating system to properly transform encoded images to the output color space. Same with printers. Those hardware can also apply further gamma corrections.

The gamma curve is exponential and described by V{\tiny{output}}={V{\tiny{input}}}^\gamma

We like RawTherapee and similar RAW developement tools because a simple gamma exponential curve is very often not good enough to present the RAW visually.

1 Like

The gamma of a CRT monitor is about 2.2. Thus a linear image appears dark without gamma correction. The gamma correction applied e.g. to JPG is a gamma of 0.4545 = 1/2.2 to compensate the gamma of the CRT. So a value of 0.4545 is the correct one in the above formula.

It is important to have the gamma of the monitor set to 2.2 for this compensation to work. Modern monitors behave physically different to CRTs but the functionality is made to mimic CRTs for backwards compatibility.

For details see e.g. Poynton’s FAQ or here.

In the second reference Poynton states my above explanation as “misconception”. However, to my knowledge, the CRT was historically the first reason to implement the gamma correction. Furthermore, in his book Poynton states “If gamma correction had not already been necessary for physical reasons at the CRT, we would have had to invent it for perceptual reasons.”

I would say that this latter statement is the correct description, as one correction fulfils the needs of two purposes - physical and physiological. :slight_smile:

Hermann-Josef

2 Likes

Where does gamma correction occur in the above figure?

I can’t understand this fully. Could you clarify it? I know that RAW images are linear and RGB images should be gamma encoded, so a gamma curve is always required. From the above figure, it seems other curves such as tone curve is applied. A gamma curve is one of the curves in the pipeline.

1 Like

Indeed. If you use ICC profiles for display and export, they contain a tone reproduction curve (TRC) that is “gamma-shaped”. It’s applied along with the color matrix/lut at the time of display/export.

Filmic and it’s ilk are really “look” curves, applied earlier. They are usually where the data departs from scene-linear.

If you mean ‘gamma’ as the ‘make the linear data suitable for display’, that’s in applying the output profile, usually sRGB. Those curves (‘transfer functions’) are defined by standards. See Transfer functions in imaging - Wikipedia.
That will still result in a dark, flat-looking file; the curves you apply processing take care of that. In a sense, all raw files are ‘underexposed’ (what we see as mid-grey is a pretty dark shade in linear light).

1 Like

Do RawTherapee need to consider display? The output jpg file is in one working color space where gamma encoding is requirement. The monitor should be responsible for displaying?

I mean gamma is a requirement for one standard working space. For artistic purpose, one tone curve is applied for one specific photograph by the user. The following link describes such curves https://rawpedia.rawtherapee.com/Exposure#Tone_Curves.

I think RawTherapee gets the display profile file from the operating system, but then has to do the display transform itself. Depends on the OS and color management system.

I’d not think of the color space in the exported JPEG as “working”. If you were using a JPEG as a transfer file from RawTherapee to GIMP for further work you could consider it “working”, but you’d want to use one of the larger linear spaces like ProPhoto for that, and really you’d also not want to use 8-bit JPEG. JPEG was designed for output renditions.

2 Likes

These curves have nothing to do with ‘gamma’. They are used as a base for converting the raw image towards the final image. The only place where ‘gamma’ comes into the game is when the image is converted to an output, be it for the monitor or a jpeg file.

1 Like

If the resultant image can look good, any kind of curves can be applied no matter what the curve is called. As the second figure shows, an internal gamma is set during the conversion from rgb to RGB. In my view, the image may not be perfect when an gamma is applied, but it can be a good starting point. With one tone curve set by users, an expcted photograph can be obtained. The procedure is easy to use.

The conversion rgb to RGB is during output, where RGB is very often represented by sRBG

In the first figure, the step 14 is Process RGB, so conversion rgb to RGB shoould be performed at or before the step 14.

A short summary about gamma.

The whole process is done with a gamma of 1.

It must be taken into account that all Lab processes (Local Adjustments, Lab adjustments, Wavelets, etc.) introduce a gamma of 3.0 and a slope of 9.03 which is reversed at the end of the process.

For Local adjustments, some tools have the ability to adjust the gamma (Lab) and bring it back to 1 if necessary. The reverse adjustment is made at the end of the tool process.

The “Abstract Profile” tool - located almost at the end of the process, allows you to adjust the gamma (and the slope) to a level perceptible by the user, thus allowing you to act on the tones of the image, or even set a gamma of 1.

At the end of the process, whether output to the screen, the gamma and slope are adjusted by default to “sRGB” - gamma = 2.4 slope=12.92. It is possible for TIF/JPG outputs to modify these values.

jacques

3 Likes

(emphasis mine)

On the main RawTherapee page you’ll find:

High Image Quality

Non-destructive, 32-bit (floating point) processing engine,

The floating point operations are also mentioned on the Features page:

performs calculations in floating point precision.

And it’s laid out in more detail on the page The Floating Point Engine.

Step 5 in the pipeline is: Scale colors (internal, no tool in UI). I assume that is the point where camera-specific (for example, 12- or 14-bit) sensor values are converted to 0…1 (or whatever standard max value the pipeline uses) floating point. (This is one of the points emphasised in The Floating Point Engine: many converters scale the incoming (e.g., 12- or 14-bit) sensor data into 16-bit integers, but RT scaling the values to floating point, which it then uses later on for all processing.)

So, internally, you’ll never have 8-bit values. While 8-bit images pretty much always use gamma encoding, gamma can also be applied to 16-bit integer values, as well as to floating point (that could use a 32-bit representation).

Edit: based on Jacques’ response, there is actually no gamma applied to internal data, except in some very specific cases, so the following text in strike-through is not applicable.
It simply means that a 10% value in the part of the pipeline that uses gamma-encoded values does not represent 10% of the 100% brightness, but rather about 1%; an 50% value means about 21% brightness, an 80% value 60% brightness and so on.

Applying the gamma to represent the data does not mean it’s applied to adapt it for viewing on a screen; you have do that with the tone curves.

And, as mentioned previously, the data is then transformed and re-encoded for your display, and also for file output, according to the standards of the chosen output format (under the Output Profile of the Colour tab), with the data representation (8 or 16-bit integer or 32-bit floating point) set under File Format of the Queue.

1 Like

Dear Jacques @jdc , that sounds logical – but does that mean calculations are done with the linear (gamma = 1) representation, but between steps, the data is stored with gamma encoding? If not, what does the following, taken from https://rawpedia.rawtherapee.com/Color_Management_addon, mean? If yes, what is the advantage of using the gamma internal pipeline storage?

During this [space-less rgb to working-space RGB] conversion, an internal gamma is set by RawTherapee that always is “gamma sRGB” i.e. “gamma=2.4 and slope=12.92”

@kofa
Yes, all calculations except those I mention are done with a gamma of 1.
The part of rawpedia concerned is old and wrong, I will (try) to correct.

Done :slight_smile:

2 Likes