[Merged] New module Contrast and Texture

Hi all!

A new module was merged to darktable master yesterday, contrast and texture, a scene referred local contrast module! Its a first step in merging the previous work of @Wilecoyote and @Christian-B which started experimenting with this new approach.

We now have a minimal version in that can get a lot more testing by the community while I continue to extend its functionality with inspiration from those two previous efforts and with feedback from you. The two things I will look at first are.

  • Some form of multiscale support
  • Shadows and highlights control

The UI looks like this now:

Here is an exampe of its usage, I quite love to use it on clouds. It uses one instance for the foreground and one for the clouds.

The noise suppression is new compared to earlier attempts. The effect now previews in the “mask” and it adds a offset to the luminance estimate before filtering and log conversion which is quite effective in reducing the effect of dark noise in log space.

If you try it out and have some feedback or ideas for step 2, please write it here in this thread!

39 Likes

Thanks for your work @jandren! Very excited to try this out :slight_smile:

5 Likes

I have been waiting for a new toy to appear before I updated from 5.6.0 stable release. The new toy has arrived! :partying_face:

5 Likes

The module is simple and does what it’s supposed to do well. :+1:

I’m particularly interested in being able to reduce the coarse local contrast. This can be very helpful, for example, in portraits to make the skin look smoother. Here’s a slightly exaggerated example for demonstration purposes. Coarse local contrast has been reduced and fine local contrast has been enhanced using a second instance:

Here’s also an example of contrast reduction in landscape photography when combined with the Contrast Equalizer:

This is definitely a nice addition. Thanks!

18 Likes

Thanks for the nice example, DoS is very slow on my computer, so I use the local constrast module and the contrast equalizer for most of my images. This could be a new way. Could you maybe elaborate a bit, what you did with the new module and what was the purpose of CE in the landscape picture?

I had problems building the package in my CachyOS system.

Just in case it helps anyone, I have had to disable IPA-CP on PKGBUILD build() function:

build() {
  cd $_gitname

  #Fix - disable ipa-cp
  export CFLAGS="$CFLAGS -fno-ipa-cp"
  export CXXFLAGS="$CXXFLAGS -fno-ipa-cp"

  [[ ! -d build ]] && mkdir -p build

I tried disabling LTO too and changing the optimization from O3 to O2, it did not work.

The output error was:

...
[ 93%] Linking C shared module libcontrastntexture.so
[ 93%] Linking C shared module libcolorequal.soduring IPA pass: cplto1: internal compiler error: Segmentation fault
[ 93%] Building C object lib/darktable/plugins/imageio/format/CMakeFiles/ppm.dir/ppm.c.o0x1739d5a internal_error(char const*, ...) ???:00x1959b9c ipa_ref::remove_reference() ???:00x1ae2969 ipa_fn_summary_t::duplicate(cgraph_node*, cgraph_node*, ipa_fn_summary*, ipa_fn_summary*) ???:00x1ada442 symbol_table::call_cgraph_duplication_hooks(cgraph_node*, cgraph_node*) ???:00x1be737e cgraph_node::create_virtual_clone(vec<cgraph_edge*, va_heap, vl_ptr> const&, vec<ipa_replace_map*, va_gc, vl_embed>*, ipa_param_adjustments*, char const*, unsigned int) ???:0/usr/lib/gcc/x86_64-pc-linux-gnu/16/lto1 -march=znver3 -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -msse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512vbmi -mno-avx512ifma -mno-avx512vpopcntdq -mno-avx512vbmi2 -mno-gfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mclzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mno-movdir64b -mno-movdiri -mmwaitx -mno-pconfig -mpku -mprfchw -mno-ptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mno-serialize -mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mno-waitpkg -mwbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mno-hreset -mno-kl -mno-widekl -mno-avxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex -mno-avxvnniint16 -mno-sm3 -mno-sha512 -mno-sm4 -mno-apxf -mno-usermsr -mno-avx10.1 -mno-avx10.2 -mno-amx-avx512 -mno-amx-tf32 -mno-amx-fp8 -mno-movrs -mno-amx-movrs -mno-avx512bmm -quiet -dumpbase ./libcontrastntexture.so.wpa -mmmx -mpopcnt -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -msse4a -mno-fma4 -mno-xop -mfma -mno-avx512f -mbmi -mbmi2 -maes -mpclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512vbmi -mno-avx512ifma -mno-avx512vpopcntdq -mno-avx512vbmi2 -mno-gfni -mvpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mclzero -mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mlzcnt -mmovbe -mno-movdir64b -mno-movdiri -mmwaitx -mno-pconfig -mpku -mprfchw -mno-ptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mno-serialize -mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mno-waitpkg -mwbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mno-hreset -mno-kl -mno-widekl -mno-avxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex -mno-avxvnniint16 -mno-sm3 -mno-sha512 -mno-sm4 -mno-apxf -mno-usermsr -mno-avx10.1 -mno-avx10.2 -mno-amx-avx512 -mno-amx-tf32 -mno-amx-fp8 -mno-movrs -mno-amx-movrs -mno-avx512bmm -mtune=generic -g -g -O3 -O3 -O3 -O3 -O3 -O3 -Werror=format-security -Wshadow -Wtype-limits -Wmaybe-uninitialized -Wno-error=varargs -Wformat-truncation=0 -Wno-error=address-of-packed-member -fno-openacc -fcf-protection=full -fPIC -fno-plt -fexceptions -fstack-clash-protection -fcf-protection=full -fopenmp -ffast-math -fno-finite-math-only -fexpensive-optimizations -fltrans-output-list=/tmp/cc6dqErE.ltrans.out -fwpa=jobserver -fresolution=/tmp/ccGzSDW2.res -flinker-output=dyn @/tmp/ccld9mlQPlease submit a full bug report, with preprocessed source (by using -freport-bug).Please include the complete backtrace with any bug report.See <https://github.com/CachyOS/CachyOS-PKGBUILDS/issues> for instructions.lto-wrapper: fatal error: /usr/bin/cc returned 1 exit statuscompilation terminated./usr/bin/ld: error: lto-wrapper failedcollect2: error: ld returned 1 exit statusmake
[2]: ***
[lib/darktable/plugins/CMakeFiles/contrastntexture.dir/build.make:209: lib/darktable/plugins/libcontrastntexture.so] Error 1make
[1]: ***
[CMakeFiles/Makefile2:9149: lib/darktable/plugins/CMakeFiles/contrastntexture.dir/all] Error 2make
[1]: *** Waiting for unfinished jobs....
[ 93%] Built target copy
[ 93%] Built target pdf
[ 93%] Linking C shared module libpng.so
[ 93%] Built target jpeg
[ 94%] Linking C shared module libppm.so
[ 94%] Built target channelmixerrgb
[ 94%] Built target primaries
[ 94%] Built target ppm
[ 94%] Linking CXX shared module liblens.so
[ 94%] Built target agx
[ 94%] Built target png
[ 94%] Built target watermark
[ 94%] Built target rasterfile
[ 94%] Built target demosaic
[ 94%] Built target colorequal
[ 94%] Built target lens
[ 94%] Built target toneequalmake: ***
[Makefile:156: all] Error 2make: Leaving directory '/home/leptom/Workspace/darktable-git/src/darktable/build'==> ERROR: A failure occurred in build(). Aborting...
1 Like

OK. Here’s what the photo looks like without the new “Contrast & Texture” and “Contrast Equalizer” modules:

The harsh local contrasts—especially in the trees and other areas around the water—make the entire scene look very cluttered and distract from the waterfall, which is the focal point of the image.

Using the first instance of the new C&T module, I reduced the contrasts at this level of detail. Now you can see how the texture appears much smoother in the trees and other areas of the image. This is particularly evident in the areas with highlights:

With the second instance, I increased the detail level to enhance local contrast in the fine details. I applied this using a mask only to the water and waterfall as the central elements of the image:

And with the Contrast Equalizer, I reduced the coarser local contrasts just a little more. I could have done this earlier with another instance of the C&T module, but I simply wanted to try it with the CE to see how these two modules complement each other:

The result was very good, so I left it as is.

The idea is basically to give the entire photo a soft look to smooth out/diffuse the busy texture so that the main subject is easier to recognize and stands out more clearly.

19 Likes

Regardless of speed I preferred the local contrast module over the DoS preset. However, I am looking forward to this new additional tool.

@jandren Did you think about how we should do the documentation? Do you want to wait until we are closer to 5.8 or should we start work on that?

Thought from testing: I think the “local contrast” control could be a bit more aggressive; I find myself applying quite high numbers to get the result I want.

What is the others experience with this?

I like this module very much. Quite a while back, I used to use local contrast module because it brought out faces (more punchy? That’s what I mean but it sounds bad) Then I found it too much, and abandoned the module completely.

This new module is very good for making very subtle changes. The sliders and mask are easy to understand. Many thanks to those involved :slight_smile:

1 Like

Testing on Mac intel, better (for my taste) results in highlights when replacing contrast equalizer and diffuse and sharpen modules. As mentioned in past above, I am also using high values of local contrast (over 90 %).
Thanks for the collaborative work you guys have done advancing this module!

Very nice result…I pushed it for some detail…maybe could have used two instances one for the foreground and one for the rocks…

Basically this is only the default AGX with the auto pickers and 120% saturation and lens correction…

Then added the contrast and texture to the second one

6 Likes

Hi Jakob … first of all congrats that your module made it into the " merged " status of DT .
Overall it does work well and it´s doing what it should do … adding or removing local or even broad contrast in scene referred WF , which is really cool !!!
For the most part … i do find it useful , apart from skin smoothing … the results look more like a plastic mess than a naturally skin . Well just my opinion :wink:.

Now comes the tricky part for me , to explain why I will not use the module …
if I want to make adjustments to different scales of the details in the image , I have to use numerous instances of the same module … which I do not like that much , personally .
I do rather prefer the " original " idea of having a " five band equalizer " to do it all in one go … for the most time .
As good as this module seem to work … I just felt too much in love with @Christian-B module , which does give all and more I do need for most of the time .
I hope you all accept my honesty … and that there is no competition amongst you guys !!!

Kind regards Andreas

Hello Andreas,

There is absolutely no rivalry. @Jandren has undertaken a complete rewrite of the module, step by step, and I thank him for that. He is in the very early stages, and unless I’m mistaken, he plans to add the other scales later, once the code is perfected for the reference scale.

Greetings from the Luberon,
Christian

7 Likes

Indeed, from the PR:

Next steps are:

  • Add multiple levels (explore highpass vs bandpass modes)
  • Add shadows and highlights control based on the low pass like a simplified tone equalizer, worked really well in my testing earlier.
4 Likes

This are good news … sounds promising and cool that there is no competition between you guys !!!

1 Like

Thanks for all the positive feedback so far!

@s7habo thanks for the examples! Keep them coming!

@rgo hmm a similar error is reported on Github but I can’t make out a lot from. Have you tried do a clean build? There is nothing fancy or new added more than the module so don’t have very good insights.

@mino I think we can start, at least the filter settings should stay pretty constant.

@helgeschneider thanks for trying! As @Christian-B pointed out this is just the first step of developing something like his effort. I encourage you to provide examples where you need multiple instances to get the effort you want, with the settings for all of them. Would be very helpful! Examples where even multiple modules doesn’t work even when you feel it should is also of interest.

I’m looking forward to your continued testing and feedback :smiley:

4 Likes

Cool; How shall we proceed? Do you have something ready to go or would you like me to get on it and refine from there?

Don’t have anything prepared so feel free to get started if you want to!

Another possible topic for contributions is the OpenCL integration, there isn’t one yet so its an open issue if someone wants to tackle that :wink: