Conditional blending, also known as “blend if”, is a feature which is currently under development in our master branch. A general description of the idea together with some examples can be found here. In short, conditional blending allows you to limit the effect of a module to certain pixels of an image, determined by their color coordinates. For modules in Lab space, you can restrict the effect of a module depending on the pixel’s L, a, and b value. For modules in RGB space, you can restrict the effect of a module depending on color channels Red, Green, and Blue plus a Gray value.
Today I’d like to describe a few recent extensions to conditional blending. All of them have the aim to give users better control to which of the pixels a module should be applied and to which not. These extensions can be found in branch blendif and should soon be merged into master.
New channels with chroma and hue characteristics
Although images normally only have three real data channels (L, a, b and R, G, B, respectively) we can define additional virtual channels and use them to better select a range of pixels. These virtual channels are calculated on a per-pixel basis only for the purpose of conditional blending. The already existing Gray channel in conditional blending of RGB modules is an example.
Modules in Lab color space now got two additional channel tabs “C” and “h”. They stand for chroma (saturation) and hue in the LCh color space – a color space closely linked to Lab. Chroma C goes from 0 (unsaturated) to 100 (maximum saturation). In real images you will hardly find pixels with a C value above 50. Hue is a parameter which describes a color circle with all possible colors at a given lightness and saturation. We express it in degrees from 0 to 360. The gradient of the slider will tell you where a certain color is to be found. You can also use the color picker to take up chroma and hue from any spot of your image.
Modules in RGB color space received three additional tabs “hue”, “chroma” and “value”, coming from an HSL color description. H (= hue) goes from 0 to 360 degrees and S (= chrom/saturation) from 0 to 100. Please note that measures for hue and chroma in HSL are different from the ones in LCh. A high value for S (close to 100) is not uncommon for RGB images; that’s different from parameter C in Lab modules. Channel “value” is just another parameter for lightness – it’s added here for convenience reasons.
New option to toggle polarity
In the previous implementation of conditional blending it was easy to select a (narrow) range of values where a module should be blended in, while all other pixels are being left alone. However, it was difficult or impossible to do the opposite – define a band of values, where a module should not be blended in.
Now you can change the polarity of each slider by an additional toggle button. A positive polarity is equivalent to the already known behavior. Switching to a negative polarity allows you to define a band of values where a module is not blended; all pixels which do not fall into this range can take effect from the module.
A poppy blossom
Let’s go for an example. I took this photo of a poppy blossom because I liked the strong color contrast effect. As the flower grows in front of a pile sun-bleached dead wood, it receives a strong accent to its intense, lively red.
On the problematic side remains a somewhat low contrast within the blossom. The petals appear a bit like a red blob, a typical problem of unprocessed raw images. The droplets, which the last shower of rain has left behind, are hardly discernible. Admittedly the blossom is a bit soft too, probably due to sloppy focusing on my side.
OK, there are a few modules in darktable which we could take to improve the image. darktable’s swiss knife equalizer comes to mind, or module highpass combined with a suited blend mode.
I took highpass with blend mode soft light in this case as it will increase contrast and sharpness, easily controlled with only two sliders. As described, I want to apply the module only to the red petals of the poppy flower; that’s why I need conditional blending.
Module highpass works in Lab mode and it would certainly be possible to select the right part of the images with the L, a, and b sliders. However, this is much easier done with channels C and h. Just take the color picker to identify the hue of the blossom and select a narrow band around this hue value. Then in addition limit the effect in chroma channel to the more saturated colors.![blendif2-1](blendif2-1.jpeg) ![blendif2-2](blendif2-2.jpeg)
With the recently added display mask option, it’s now very easy to see what gets blended and what not. The yellow color shows you that we really only selected the petals of the poppy, everything else remains unaffected.
Here is the resulting image with some additional contrast enhancement.
Now let’s assume we would want to turn this natural almost-colorkey image into a full colorkey (just for demonstration purposes; personally I do not like colorkey in most cases).
If we want to gray out all parts of the image except of the petals, we can use our monochrome module and use blendif’s new polarity option. Again we define a narrow band around the red hue of the blossom but this time with inverted polarity.
Here is the result of our exercise:
When exporting images with highly saturated colors like this – where colors are relevant for the message of the image – you might experience some disappointment. If you have a wide gamut monitor like me and then export into a JPEG in sRGB color space, part of the color variation you achieved may get lost again. That’s because saturated colors may be well within the gamut of your monitor, but are already out of gamut for sRGB. Choosing AdobeRGB as output profile combined with a different output intent (like relative colorimetric instead of perceptual) in darktable’s output color module can help to improve the situation.