Trying to emulate Adobe's clarity in RawTherapee

Ok here is Firefox Send

In Lightroom - from -100 up to +100

Dear all,
first of all, thanks a lot @DxO-user and @Nick_Auskeur for the samples!

From a first look, it seems the result of some kind of histogram equalization… maybe an edge-preserving CLHAE derivative?

Look for example how the contrast on the horse gets enhanced much more than the contrast in the building walls…

Some slight halo is also visible, for example where the horse leg is brightened near an already bright road patch:

There is also some uneven brightening where the bright road patches are smaller:

Halo is a known side effects if you push the Clarity too much.
Reduce the Clarity , or use it as a part of local adjustment.

As I may have said in another thread, it is a combination of techniques. The newest iterations use machine learning as well. In general, they tweak the formula once in a while.

I try to open the link “Firefox send”, but it tells me that the link has expired. I tried tuesday,…today

jacques

@jdc
I uploaded it one more time. I even included +25%
house -100
house -50
house 0
house +25
house +50
house +75
house +100

@DxO-user I am assuming that you are using the latest process version (which is at 5 right now; see: https://helpx.adobe.com/creative-suite/using/process-versions.html).

The reason that I bring this up is because post Version 2 (2010), the default processing is quite developed, even when sliders are at neutral.

Although clarity is probably a completely different beast in version 2 in comparison to 5, it would be great if you could provide version 2 clarity samples.

@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.