darktable article lede image
Some enhancements to conditional blending
Ulrich Pegelow

Some enhancements to conditional blending

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.

IMG_4287x_0001

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.

blendif2-3

Here is the resulting image with some additional contrast enhancement.

IMG_4287x_0002

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.

blendif2-4

Here is the result of our exercise:

IMG_4287x_0003

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.

Filed under: Blog Community Development Blending Color Conditional Blending Darktable Lab Monochrome Saturation
These are comments from the old website, archived as static HTML
  1. Do you have an idea of when (what version number) this will make it to stable?
  2. Conditional blending is already part of our current git master. If there are no objections, the additional features described in this article will go there too. So hopefully you will find all of this in darktable 1.1.
  3. nice! will be in a near future a similar implementation using a brush or similar? to make it locally by space not colors. thanks for your work!
  4. there is some development ongoing. but since this is rather complicated don't expect this soon.
  5. limaunion on Tue Jul 17 10:39:44 2012:
    just wanted to thank the developers, DT is really impressive, hope to find more improvements in the near future and bug #8767 (memory leak) solved asap.

    If you want to check some of my photos taken in the Andes Mountains retouched with DT visit: http://goo.gl/10YUU

    Keep your excellent work!
  6. kellpossible on Mon Jul 23 04:20:08 2012:
    Also just wanted to thank you guys. This software is fantastic! Going to tell all my photo taking friends about it. Only thing I can't figure out is how to switch between photos using arrow keys in darkroom mode using the git version. Also your website is very impressive. Congrats, and keep it up. Not sure how effective the opencl support is but it's a great idea.
  7. Hi,

    you can check (and change) all the shortcut keys in darktable's preferences. If I recall correctly the default keys for switching images in dr are space and backspace.

    regards,
    Simon
  8. I try and quickly adopt it. It's a really nice and great enhancement for darktable. I think it will be interrinsting in the future to have more possibilities for create and also blur or modify the mask.

    thanks
  9. Have a look at branch "blendif". It features an option to add gaussian blur to the mask.
  10. Y discover it and yes ! i think that a really good imrovement has been done with the possibility to add some bulr to the mask.
    The final touch would be for me to add the possibilty to modify directly the mask with a brush or some thing else (like Bibble for exemple). I don't know if you can do it easly... anyway, thanks for your work !
  11. i love this program because it's very easy to use and it's awesome.So think you for making this program