Trying to emulate Adobe's clarity in RawTherapee

@DxO-user

Thank you, now I can upload :slight_smile:

But very big files

jacques

Yes I’m using the latest version in Lightroom 8.2 ( the same as in Adobe Camera RAW)
I was getting the latest update a few weeks ago.

I think, of course, I do not have the code, that adobe uses an “EPD” (edge preserving decomposition).

You can see this effect, in the “blue horse” image and also (less) in the Venezia image.

With Rawtherapee you have now several ways to perform a function “clarity”…I don’t speak to “copy” Adobe, which for me does not make much sense, every software has its algorithms, its process.

Branch “wavelenh” - function “Clarity” - by using Residual image…and others effetcs

Branc “newlocallab”, several “local” tools, combining with “scope”, transition, etc…that can be used alone or in combination

  • CBDL - in fact it’s simplify wavelet (Harr), with Clarity
  • Tone-mapping (edge prererving decomposition)
  • Local contrast
  • Retinex - which is using an algo close to “local contrast” but more complex and for much larger radius values
  • masks to change gamma

jacques

1 Like

Inspired by the clarity version of the blue horse image, I have started experimenting with “adaptive contrast stretching” techniques, and the result are rather promising:

I still do not like the way the algorithm handles the bright areas, but I find that the horse gets instead a very nice pop.

What do you think?

Of course I will share the details as soon as I have something reasonably good at hand!

3 Likes

I have always had trouble with the bright areas myself when developing techniques. ATM, I am just masking them out and / or treating them separately. In images where there is a clear separation between the light and dark, it is relatively simple as long as you threshold properly. Simple doesn’t always mean easy though. :stuck_out_tongue:

Disclaimer: this is by no means a sort of reverse engineering of the Clarity tool, it is instead a mere comparison with well-known image processing algorithms

Today I made another interesting observation regarding the way clarity works.
In fact, the basic algorithm seems to be quite simple, and well known. It can be summarised like this:
R = L/L_{mean}
L_{out} = L * R
RGB_{out} = RGB * R

That is, the input RGB values are scaled by the ratio of the RGB luminance over a local mean value.

To demonstrate this, I have divided the Clarity=0 blue horse image by a constant value, and used the formula above to create an equivalent of the clarity output. Here are two crops, corresponding to two different choices for L_{mean}, one around 0.5 for the bright stone wall, and one around 0.05 for the dark doorway. Here are the results:

Clarity=100 stone wall crop:

My formula on the stone wall crop with L_{mean} = 0.5:

Clarity=100 dark doorway crop:

My formula on the dark doorway crop with L_{mean} = 0.05:

Of course, this is just the tip of the iceberg… the main challenge is of course to implement a good edge-preserving averaging method. I will see what I can obtain with the incremental guided filter I am using for the shadows/highlights tool.

Hopefully, more news will follow… :smiley:

1 Like

Bare bones attempt. Photoflow: linear no-clip minimal. G’MIC: filter pixels, resize 50%, 3 curves, algorithm, 2 curves, sharpen, resize 1800px.


Crop attempt. Less G’MIC processing than above. Photoflow: linear no-clip minimal. G’MIC: filter pixels, crop, gamma, algorithm, 2 curves.

No algorithm

Algorithm (1 strength)

Algorithm (1.5 strength)

Several PP3
I always use branch “newlocallab” commit 7f8b5bf

A) 2 pp3 to “simulate” Adobe, with Venezia image
I start with House0

  1. with local CBDL
  2. with local Tone-Mapping (pay attention to the output processing time TIF or JPG)

B) 1 pp3 - only on the blue-horse with image “2010_MONTR_033.NEF”

  • combination of CBDL and Tone-mapping

house0.tif-CBDL.pp3 (22.9 KB)
house0.tif-TM.pp3 (22.9 KB)
2010_MONTR_033.NEF-TM-CBDL.pp3 (17.5 KB)

Of course all these results are choices according to taste, more or less effects, for educational purposes - show various tools

jacques

Some more investigations and observations, based on the Clarity=100 blue horse image.
First of all, in the following I will make the hypothesis that clarity enhances the local contrast using the “ratio” formula I introduced here, and which can be re-written as
L_{out} = L^{2}/L_{mean}
If the above formula is valid (even approximatively), it is then possible to derive the L_{mean} image from the input and output:

L_{mean} = L^{2}/L_{out}

that is, take the clarity=0 image, multiply it by itself, and divide by the clarity=100 image.

I did the exercise, and this is what I obtained. I let you look in detail at the image and its properties…


An high-resolution TIFF file is available here.

I have been experimenting quite a lot with local contrast those days. The algorithm I am developing is still based on my “incremental guided filter” for the image smoothing, using the “ratio of values” approach I outlined above.

What I added on top of the basic algorithm is some code that protects highlights and dynamically adjusts the enhancement of the local contrast based on the tonality of the blurred image. Shortly speaking, in regions where the blurred image is bright the code emphasises more the dark details, and vice-versa in dark regions. Dark and light details are enhanced symmetrically around mid-tones.

Here is what I am obtaining with the house image (I need to post a full-res image because details here really matter):

I hope to be able to commit the code in PhF during this weekend. I can also explain the details of the algorithm is anyone is interested…

Please notice that this has nothing to do with LR’s clarity tool. In particular, it is clear that clarity introduces some “smart” local tone adjustment, using I guess a rather non-trivial logic. See for example the house image at clarity=100%, and how the bright areas at the bottom-left are darkened much more that the walls of the building on the right…

5 Likes

Once you have committed the code, please share your PFI in the post above so that we may play with the module and see how you have set up the pipe prior to its application. That way we can compare and contrast. And maybe a before image for those who don’t want to examine the PFI.

As the content of the thread has moved to a PhotoFlow implementation, wouldn’t it be better to split it into a PhotoFlow thread?

Guess so. But, I guess once @Carmelo_DrRaw is finished, the g’mic implementation can exist soon, so that might come up.

@heckflosse I think it is fine. Although the app in the latter half of the discussion is PhotoFlow, the discussion has been on the strategies. Perhaps, we could change the category to the more general Processing and then tag away the rest (ATM, RT, PhF and briefly G’MIC).

@Reptorian Are you suggesting that you have something in the works? I have already been using a bare bones version that I demonstrated above. Not the best example images but it worked in my latest PlayRaws. As with almost all of my commands, they never reach community.

I don’t quite agree… I’m just experimenting with the processing pipeline I am most familiar with, but whatever I come up can be ported to RT. It would have simply taken me much longer to experiment in RT directly.

@heckflosse @agriggio as a first step, I would suggest to reproduce in RT my suggested “incremental guided filter”, as the basis for the local contrast adjustment. The description given here should be already quite detailed, but if anything is not clear just ask me.

The rest is just some rather trivial pixel manipulation in log space, and I simply need few hours to write down the formulas. Meanwhile you can have directly a look at the code here.

2 Likes

No link, but finally here is some help to know what those sliders do:


Clarity in RawTherapee

This is a wavelet module to increase local contrast and local saturation. It enhances the details (luminosity and chromaticity) of the selected level and below, and merges them with everything else above the selected level (the residual image) in a way that improves the appeareance of the image.

When you turn on the Sharp-mask and Clarity module with Clarity method: Clarity , the configuration of the wavelets (at the beggining of the tool) will automatically be changed to:

  • Background: residual
  • Process: Above the level
  • Level 7

If you turn off the module, Process will go back to All levels in all directions .

While the other settings must remain untouched, you can change Level 7 and set a higher (8 and above) or lower (6 and below) level. The higher the level, the more powerful the clarity action will be. In other words, the lower the level, the fewer the details that will be enhanced, and the more subtle the action will be.

As soon as you turn off the module or select again All levels in all directions , the effect of the clarity dissapears: the tool needs the proper settings in the configuration for the module to work. In spite of this, the settings within Clarity are not lost, you just have to select again Above the level (or turn on the module) to get the clarity effect again.


When you Merge Luma (luminosity), sliding to positive values enhances the contrast of details, while sliding to negative values makes the image more dreamy, fuzzy .

When you Merge Chroma (chromaticity), sliding to positive values enhances saturated colors, while less saturated colors get less variation. Sliding to negative values makes the image less vivid, while maintaining the less saturated colors mostly untouched.

Soft Radius allows you to smooth out halos without affecting much the rendering. However, this is not without side effects: dark areas will become darker, and more and more areas will be considered not contrasty enough to be enhanced, so will remain untouched.


Hope this helps, although I’m not really sure if it has relevance yet, the way the post has evolved.

I wish to thank Jacques Desmis (@jdc) for his help.
Xavier

2 Likes

Thanks for the explanation. I never used this but that is what I do sometimes in my own G’MIC processing, though it likely isn’t as sleek as @jdc’s. :blush: I often find that the stuff I do so happens to parallel what other people have been doing already. A good sign that I am doing something right with my random processing and experimentation. :stuck_out_tongue:

1 Like

I played a little bit in RT with the two images (“Blue” horse" and “House”), and 2 tools from the recent “Local Adjustments”: “clarity” (from the Contrast by Detail Levels) and “Retinex”.

Blue Horse “base” image:

Blue Horse “clarity+50”:

Blue Horse “clarity+50” + “Retinex”:

Blue Horse “clarity+100”:

Blue Horse “clarity+100” + “Retinex”:

House “base” image:

House “clarity+50”:

House “clarity+50” + “Retinex”:

House “clarity+100”:

House “clarity+100” + “Retinex”:

Note that:

  • there’s no sharpening applied
  • I have also a light amount of Dynamic range correction applied on both (amount 20)
  • I added a single local adjustment spot over the entire image, with the spot “Transition value” set to maximum (95) and “Scope” values set to 100 for both local adjustment filters (in order to affect most of the image which, I know, is not the original purpose of Local Adjustments…)

Retinex is very powerful (in the sense that it easily can go really over the top), but I think that combined with clarity, both applied with taste, can give really good results.

Edit:
here’s a screenshot showing the settings I used in Retinex:
Screenshot_2019-05-23_11-06-07

Edit 2:
the Retinex examples are wrong, they were obtained with a buggy code.

@sguyader

Thank you for all these tests and examples

Note, that I solved the “huge” bug in “Retinex”…
I also add a new “mode” in Retinex, when you choose “scale = 1” Local Retinex have a behavior close to “local contrast”, but with values and results differents…

2 Likes

Thanks Jacques, I’m going to check this.