darktable is an open-source software for raw photographs management and processing developped since 2009 for Linux desktops. Since then, it has been ported on Mac OS and Windows 7, 8, 10. After having used it for 7 years, I begun to develop in it 3 months ago. This article shows my work and results to improve the HDR-scenes handling in darktable, in a fashion that allows better color preservation for portrait photography.
The beginning of this article is mostly directed toward a general audience, until the section Controls, which provides a complete manual showing how to use the new filmic module. The next sections are mostly directed at scientists and technical audience.[WARNING : DRAFT - WIP]
Table of Contents
- About HDR and dynamic range
- About darktable’s filmic module
- Place in the workflow
- Use cases
- Comparison with other darktable’s tonemapping methods
- logarithmic shaper
- Filmic S curve
- Known issues
- Further editings
- logarithmic shaper
Even though HDR is a big thing right now in the LED screen industry, and this term is wildly used to describe anything for marketing purposes, it is useful to recall what it is. The dynamic range is the interval of measurement between the sensor detection level (ground level) and its saturation level (ceiling level). Generalized to the eye and translated into human perception, it is the range of lightness between what is seen as pure black (no lightness) and what is seen as pure white (blinding lightness). For optical applications, this bounded range can be expressed in terms of 2-based logarithmic intervals, the exposure values (EV), also called stops in the photographic industry, that are believed to be evenly spaced in human vision.
While the dynamic range of the average human eye is estimated between 22 to 24 EV, consumers displays reach roughly 10 EV, and 8 bits JPEG files can, by design, encode no more than 8 EV. This has quickely become a problem with high-end DSLR reaching now almost 15 EV (Nikon D7200, D750, D810, D850, Sony A7 , A7 RIII, Hasselblad X1D, Pentax K1, 645z).
Although “HDR” in photography has often the meaning of multi-exposure stacking and tone mapping technic (to compensate for the low dynamic range of now outdated cameras), an high dynamic range can be generally defined as any source dynamic range that is higher than the dynamic range of the destination medium. That triggers the need to remap the input dynamic range to the output one in a fashion that prevents clipping and retain as much details as possible. This is a technical challenge, leading to some trade-offs, and can be done in two different (and perhaps combined) ways : [ref]Tone mapping, Yung-Yu Chouang, www.csie.ntu.edu.tw/~cyy/courses/vfx/10spring/lectures/handouts/lec04_tonemapping_4up.pdf[/ref]
- with local tone mapping, using local contrast preservation algorithms, often resulting in halos and unrealistic pictures,
- with global tone mapping, aiming at photographic tone reproduction, derived from Ansel Adam’s classic zone system, using global transfer functions, often resulting in color issues and local contrast compression.
darktable has 3 modules implementing such transformations (tonemapping, global tonemapping and base curve) but their problem is they come too soon in the pixel pipe (which has a fixed order of filter application), some before the input color profile, some others working in Lab color space, introducing non-linearities in the RGB signal that often make the colour editing tedious and unpredictable.
The new Filmic module is a photographic tone reproduction filter aimed at reproducing the color and luminance response of analog film, dealing with dynamic range issues and gamut clipping issues (oversaturation in deep shadows and highlights). It derivates from the filmic module introduced into Blender by Troy James Sobotka, but differs in some aspects of the implementation and adds more features. The whole idea of tonemapping/dynamic range scaling implies that trade-offs have to be made to overcome the dynamic range shrinking. The choice that has been done here is to degrade the photography in a visually-pleasing way because traditionnal film has already shaped our visual aesthetics.
It works in three steps :
- apply a parametric logarithmic shaper, used to rescale the RGB values in a perceptually uniform space,
- create an “S” filmic tone curve to bring back the contrast and remap the logarithmic grey value to the display target value,
- do a selective desaturation on extreme luminance values, to push the colors to pure black and pure white.
By design, it will compress the dynamic range and the gamut (by reducing the saturation in bright and dark areas) in a way that preserves the mid-tones and compresses more aggressively the extreme luminances. This is especially useful when doing portrait photography, where skin tones are usually close to the middle grey, but is will need an extra care in landscape photography, especially for sunset pictures where the sun is in the frame background.
The filmic curve it produces simulates the tone response of classic film, with a linear part in the middle (called the latitude), and curved parts at the extremities (a toe and a shoulder). This kind of curve is similar to the presets applied by cameras manufacturers in their in-camera JPEG processors, and that can be found in the base curve module of darktable. However, these curves are applied too soon in darktable’s pipe and are not parametric. Filmic will essentially fulfill the same needs with some additional sweeteners and more configuration
Most users will need to reconsider their workflow to fully take advantage of filmic.This module should be enabled after :
- the white balance module, in order to work on balanced RGB ratios,
- the exposure module, if needed, to recover as much dynamic range as possible in a linear way,
- the demosaicing module, using high quality algorithms with color smoothing, to avoid artifacs in low-lights that could perturbate the auto-tuner of filmic (especially the black exposure).
Proper exposure settings can be checked prior to filmic use, using the global color picker Lab readings, and are achieved when :
- no pixel has a luminance higher than 100 % (no clipping)
- no pixel has a luminance lower than 0 % (as much as possible, that is not always possible)
- white skins have an average luminance of 65-85 % in Lab space
- black skins have an average luminance of 25-45 % in Lab space
- tanned skins have an average luminance of 45-65 % in Lab space
- non-human subjects have an average luminance around 50 % in Lab space (excepted deliberate use of low-key or high-key)
Color corrections should come after this module for better readability of the colors. This module can replace base curves, tone curves (to some extent), unbreak color profile, global tonemapping and shadows-highlights modules. It is not recommended to use it in combination with base curves, unbreak color profile and global tonemapping.
- the classic darktable edit makes use of the Sony-like base curve and the tonemapping module (defaults parameters),
- the default filmic output makes use of the filmic module only with default parameters, then grey sets at 1.28 % and latitude sets at 6.50 EV (settings as shown in the above screenshot),
- the filmic variant 1 enables the chroma preservation in filmic and decrease the extreme saturation to 20 %.,
- the filmic variant 2 is similar to the variant 1, with saturation decreased at 75 % in the color balance module,
- the filmic variant 3 is similar to the variant 2, with a parametric mask excluding the highlights (feathering radius : 250, blur radius : 100, key luminance : 50, feathering guide : output image).
This shot was taken in July at around 2 p.m., under trees. The color recovery is quite challenging since there is direct sun light as well as green light reflected by the foliage and the grass, so the camera adjusted the white balance to revert the green cast by shifting the tint, making the direct sunlight look magenta. The white balance used here is the one set by the camera.
- the classic darktable edit makes use of the Nikon-like alternate base curve and the tonemapping module (defaults parameters),
- the default filmic output makes use of the filmic module only with default parameters and grey sets at 2.87 % and latitude at 6.14 EV,
- the variant 1 enables the chroma preservation in filmic, with saturation set at 15 % in filmic and the saturation set at 65 % in the color balance module
- the variant 2 is is the same as the previous but with the grey value adjusted to get a more natural skin tone (2.44 %), saturation at 12 %, latitude at 7 EV, and further editing in the color balance module, to remove the green color cast from the light reflected by the foliage and the grass.
- the variant 3 derivates from the previous, increases the contrast at 1.555, reduces the latitude to 6.10 EV, the saturation to 10 %, and uses an extra RGB S curve in the tone curve module.
Note : you can download the JPEG files and import the darktable settings directly from their embedded XMP tags as if they were XMP sidecar files.
The sunset picture shows the advantages and the limits of the filmic module : while the local contrast is better preserved in shadows, with improved sharpness compared to the tone mapping version, the highlights get more compressed and heavily desaturated without the chroma preservation. There are several ways to overcome this issue :
- increase the saturation parameter above 100 %,
- use a parametric mask to exclude partially or totally the highlights.
The desaturation, while expected and desirable, is excessive in highlights with the default parameters. This can be compensated by adding more saturation in another module, color balance for example, or by using the chrominance preservation option in filmic (see below). In this case however, the problem is reverted and the saturation becomes excessive, so it needs to be dampened instead.
The chrominance preservation keeps more saturated colors, all over the dynamic range. Despite its goal to retain the original RGB ratios (relatively to the luminance), and therefore avoid hue shifting, the very bright areas of the sky shift nonetheless from orange to pink. The causes of this shift will be analysed in the section Discussion.
The second picture shows clearly the benefit of the filmic approach in portrait photography. The grey level is the key to get the right skin tone. The selective desaturation in highlights prevents the skin patch exposed to the direct sunlight from becoming either magenta or yellow, and the magenta highlights of the red dress shown in the classic darktable edit are avoided.