Toolchain Pipeline

Toolchain Pipeline and Colorimetry

1 Toolchain Pipeline

1.1 Processing order

Everything that happens to an image, from the moment you open the file to the moment it is displayed on screen or saved, takes place in a fixed order. The data flows from one module to another - this is the toolchain pipeline. RawTherapee contains four pipelines (one for the main preview, one for the saved image, one for the thumbnail, and one other that currently escaped me). The following list shows a simplified order of operations:

  1. Preprocess
    1. Dark frame
    2. Flat field
    3. Bad pixels
    4. Hot pixels
    5. Scale colors (internal, no tool in UI)
    6. Raw black point
    7. Lens distortion correction
    8. Green equilibration
    9. Line noise filter
    10. Chromatic aberration Correction
    11. Raw white point
    12. Raw histogram
    13. Prepare Auto Exposure
  2. Demosaic
  3. Retinex
  4. Highlight recovery
  5. White balance
  6. Crop
  7. Convert colorspace
  8. Noise reduction
  9. Dehaze
  10. Dynamic range compression
  11. Auto-match tone curve
  12. (Local Adjustments branch) avoid color shift, Log encoding, blur and noise, denoise, contrast by detail levels, vibrance, soflight, local contrast, wavelet, sharp, retinex, exposure, color and light, avoid color shift
  13. Tone response curve
  14. Process RGB
    1. Channel mixer
    2. Tone curve
    3. Highlights
    4. Shadows
    5. RGB curves
    6. HSV curves
    7. Color toning
    8. Film simulation
    9. Black-and-white
    10. L*a*b* color correction grid (Lab)
    11. Shadows/Highlight (Lab)
    12. Local contrast (Lab)
  15. Process Lab
    1. Lab adjustements
    2. Vibrance
    3. L*a*b* color correction grid (Lab)
    4. Vignette filter
    5. Graduated filter
    6. Tone mapping
    7. Impulse noise reduction
    8. Defringe
    9. Edges
    10. Microcontrast
    11. Sharpening
    12. Contrast by Detail Levels
    13. Wavelets
    14. Soft light
    15. CIECAM02
    16. Resize
    17. Post-resize sharpening
  16. Final Lab -> RGB conversion

1.2 List of all tools in RawTherapee:

  • Generic/Main preview
    • Input profile
    • Monitor Color Profile
    • Working profile
    • Output profile
    • Clipping indication
    • Red/Green/Blue/Luminosity/Focus mask previews
    • Colorimetric intent
  • Exposure Tab
    • Exposure
    • Shadows/Highlights
    • Tone Mapping
    • Dynamic Range Compression
    • Vignette Filter
    • Graduated Filter
    • Lab Adjustments
  • Detail Tab
    • Sharpening
    • Local Contrast
    • Edges
    • Microcontrast
    • Impulse Noise Reduction
    • Noise Reduction
    • Defringe
    • Contrast by Detail Levels
    • Haze Removal
  • Color Tab
    • White Balance
    • Vibrance
    • Channel Mixer
    • Black-and-White
    • HSV Equalizer
    • Film Simulation
    • Soft Light
    • RGB Curves
    • Color Toning
    • Color Management
  • Advanced Tab
    • Retinex
    • CIE Color Appearance Model 2002
    • Wavelet Levels
  • Transform Tab
    • Crop
    • Resize
    • Lens/Geometry
      • Rotate
      • Perspective
      • Profiled Lens Correction
      • Distortion Correction
      • Chromatic Aberration Correction
      • Vignetting Correction
  • Raw Tab
    • Sensor with Bayer matrix
      • Demosaicing
      • Raw Black Points
      • Preprocessing
      • Chromatic Aberration Correction
    • Sensor with X-Trans matrix
      • Demosaicing
      • Raw Black Points
    • Raw White Points
    • Preprocessing
    • Dark Frame
    • Flat-Field
    • Film Negative
    • Capture Sharpening

2 Colorimetry

2.1 Colorimetry – what is the importance of Ciecam and Lab ?

Colorimetry gives rise to much debate and we have to remember that it is not an exact science. No amount of equations, however complex, can ensure that the human eye will necessarily be satisfied with an image. For example :

  • it is often said that L*a*b* is non-linear and that it "distorts" the colors in particular for blue-violet and red-orange. This is certainly true if you simply adjust the image using curves or chromaticity sliders. However in Rawtherapee, if you click on "Avoid Color Shift", nearly 200 LUTs will correct these shifts and make the image perfectly linear.
  • it is also said that L*a*b* addresses imaginary colors if the working profile allows it. This is also true but again, this can be compensated in Rawtherapee by enabling "Avoid Color shift". In this case, a relative colorimetric correction is applied to the working gamut as follows:
    • it examines the image data
    • if it is within gamut: no action
    • if it is outside gamut: the chroma is reduced and if this is insufficient, or if it is close to L=0 or L=100, then L is adjusted.
    • if the saturation has been adjusted (chroma, vibrance,…), a Munsell correction using nearly 200 LUTs is applied. This will correct any color shifts with a high degree of accuracy e.g a red that has turned orange because of Lab, will become red again. There will still be some errors but they are very small.
  • Lab* is a reversible transformation of XYZ (in simplified terms, Y is transformed into L* using a gamma of 3.0 and a slope of 9.03). Lab* has more or less the same characteristics in terms of its limits (those of the primaries) as XYZ, which serves as a reference for the "Working Profile" and determines the basis of the gamut. Therefore Lab* and XYZ have 'substantially' the same characteristics (exposure range, gamut, etc.). One point however, in many processes the values of L* can be bounded (clipped), to limit artifacts (high contrasts, highlights...).
  • it is often said that "Ciecam02" is not able to process high dynamic range and wide color gamut images, which is partially true. A number of improvements were made by the development team a few years ago to mitigate this problem (bearing in mind that a large number of user images fall within the sRGB gamut and do not pose a problem). However, by using "Log encoding" in conjunction with Ciecam02 the vast majority of problems can be solved. Of course some images will still present problems, in particular with highlight reconstruction, but this is not specific to Ciecam.
  • Ciecam02 is one of the only ways to achieve true colorimetric correction because it takes into account human perception and the surrounding environment. With Ciecam for example, any adjustments to the luminosity and/or the saturation, will take into account the image and its environment.
  • White balance is also subject to debate. The "Itcwb" (Temperature correlation) module recently introduced in Rawtherapee is almost mathematically (cognitively) perfect. It makes the xyY colors of the image coincide with known spectral data. However, on images where the temperature deviates a long way from D50, the colorimetry will not be correct because there will not be the necessary chromatic adaptation expected by our eyes and brain. Ciecam however, can take this into account.

2.2 Importance of the linear-RGB mode and colorimetry

The RGB model, and in particular, the linear RGB model is often praised. It is certainly the best way to carry out "upstream" processing (demosaicing, white balance, defringing, chromatic aberration correction, etc.). Anything that can be done in this mode should be.

So what about tone curves?

  • Not only are they non-linear but they only provide limited colorimetric compensation, if any (with the exception of the Perceptual mode, which uses Ciecam02). This is in contrast to the Tone Response Curves -TRC- used for output (monitor, TIF etc.)
  • The "Auto matched Tone Curve", which is a copy of the in-camera TRC is applied mid-process and also breaks the linearity of the processing pipeline.

And saturation?

  • Maintaining RGB linearity when you change the saturation is not impossible but it is difficult and is not implemented in Rawtherapee. On the other hand, if you adjust the saturation using Ciecam, it will take into account variations in luminance (or brightness) and adapt the color accordingly.

In conclusion, there is no right or wrong way. Rather the advantages and disadvantages of RGB, Lab*, and Ciecam need to be understood and used appropriately.