Recovering highlights with dcraw using LCH blending

Note: This page has been made obsolete by newer versions of dcraw which implement a similar idea with the -H 2 option

Which issue are we trying to solve here?

Dcraw provides a -H option which allows one to choose how to reconstruct the color information of one pixel when at least one channel (R,G or B) is blown out. I was however not satisfied with the results for any of the possible parameters.

Unfortunately, none of those options make for a nice fade to neutral when two or more color channels are blown.

This patch (v2 does not use CIE-Lab any longer on a suggestion by Dave Coffin, v3 supports GMCY sensors) - applies cleanly on dcraw 8.69 - implements the following algorithm to remedy the issue:

  1. Calculate the completely unclipped value for all channels. - basically the channel values as computed by -H 1 -
  2. Calculate the clipped values for all channels. - basically the channel values as computed by -H 0 -
  3. Convert both clipped and unclipped RGB values to LCH coordinates(Lightness, Chroma and Hue)
  4. Set the LCH value of the output pixel to be the L and H from the unclipped pixel and set the C from the clipped pixel
  5. Convert back to regular RGB coordinates.

Short explanation

One can hope that the hue and lightness information from the unclipped value are approximately correct. However, one wants the saturation of the colors to be lowered for badly blown areas - similarly to the way film saturation behaves -. This is exactly what using the chroma channel from the clipped pixel accomplishes since clipping tends to desaturate. (Chroma is basically a device independent way of looking at saturation for our purpose).

Usage:

The -G option enables LCH highlight blending. This option and the -H option are mutually exclusive.

A few examples for v1 of the patch:

The first 4 columns use the exact same dcraw parameters except for the -H value. The last column adds a gimp/cinepaint/showfoto curve tweak to increase contrast in the highlights

dcraw -H0 dcraw -H1 dcraw -H3 LCH patch LCH patch + curve tweaking