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…