Enhanced Unsharp Mask in PhotoFlow - please test!

@Silvio_Grosso @afre @gadolf

I have further updated (and hopefully improved) the “enhanced USM” sharpening method.

The new code takes a simpler approach, a consequence of the fact that I realized that the guided filter boils down to a simple linear combination between the input and blurred images, at least when the input and guide images coincide. That means that by swapping the input and blurred images in the linear combination it is very easy to obtain an “inverse guided filter” that blurs strong edges while preserving fine textures.

So the new code works like this. I create two guided filter images, one inverted at low threshold to avoid blurring the noise, the second one with an higher threshold to avoid blurring the very strong edges (which would otherwise lead to the typical over-sharpening of standard unsharp mask). The second guided filter takes a log10-encoded input for better control over strong edges.
The two guided filter outputs are then combined such that areas that are not blurred in either output will also be preserved in the combined one.

Here is an example of a macro shot that show quite well the drawbacks of standard USM (noise enhancement and strong over-sharpening of sharp edges, with an unpleasant very dark halo on the dark side of the edge).

Input image (zoomed 2x)

Standard USM with radius=2px

Enhanced USM with radius=2px and threshold tuned on the image

I am personally very much satisfied with the result, but it would be really good if others could stress-test the algorithm on different images, to see if an optimal setting can be found in all cases and if the result is always satisfactory…

The build is in progress, new packages will be available from here as usual.

Thanks in advance!

@Carmelo_DrRaw Andrea, can you share the raw file?

@heckflosse I just created a play raw for you to play with it :wink:

1 Like

Thanks, it looks much better than the previous version, specially regarding noise.

And clever algo!

In this particular image, I struggled a bit to reveal detail in the stone of the bridge pillar. The low threshold seems to do the job, but it was a bit hard to prevent the rest of the image getting that standard usm look. As for the high threshold, I didn’t quite understood it.

Before

After

Can you do better?

IMG_6061.cr2 (13.6 MB)

This file is licensed Creative Commons, By-Attribution, Share-Alike.

Here is my attempt:

Concerning the meaning of the threshold values:

  • when the low threshold gets smaller, the noise is less “protected”
  • when the high threshold gets higher, strong edges are more and more sharpened

Start by putting both sliders in the middle of the range and the amount at the maximum, then lower the first one until the noise starts to get sharpened (zoom at 2x to better see the effect). Next increase/decrease the high threshold until the over-sharpening disappears. Finally, adjust the amount to taste.

Yes, this IS a bug… will look into it.
Thanks!

Nice! and thanks for suggesting the approach.

Better looking at it, I noticed a thin halo (probably not visible in the screenshot):

Hello @Carmelo_DrRaw

Just tried the new algorithm on Windows 10 (photoflow-w64-20191102_2121-git-enhanced-usm-ce38236b53b4fc8490ea1d3d74daeb86bea50d7b).
Overall it works great as far as the noise is concerned.

As regards the haloes around the sharp edges I don’t understand how I can reduce them.
I have tried to keep the “threshold low” slider at the maximum amount but they are still present.
I suppose you can not entirely avoid them, right?

Here is an example (NEF - Nikon D700).
Take a look at the lizard “fingernails”:

BTW, greetings from Turin. I am happy you have lived in the same city in the past :slight_smile:

I noticed that the halo is reduced if the sharpening goes after the raw developer layer.
But then dark edges seem to get stronger (look at the bridge pillars in the background)

Before:

After:

I did some comparison between your edit and my new code, to see the differences in sharpness.
Left is my version with radius=1, amount=400, threshold_low=10 and threshold_high=50. The input image is the RT output without sharpening.
Right is your RT version (I have used a build from the current RT dev branch).

My feeling is that your sharpening produces crisper details, on the other hand my version, while slightly softer, has smoother transitions between sharpened and non-sharpened areas.
All-in-all this is only visible when pixel-peeping at 1:1 or more, while already at 1:2 the two versions are practically undistinguishable…

Could you post the pfi file? This image seems to provide a good test case for checking the halo reduction mechanism.

Sure, here it goes.
IMG_6061.pfi (31.5 KB)

As a RT user I have to say that despite loving the new sharpening methods in RT I think the main downside is the grainy transition between sharpened and unsharpened areas. In the example above it’s barely visible but can occasionally come out stronger. I think the vulnerable scenario is transition zones between in and out of focus. ping @heckflosse

To my eyes the RT version above is a fair bit sharper without affecting the noise.

1 Like

Do you observe that only when using a dual-demosaicker or also when using plain amaze/rcd?
Btw: capture sharpening works best with rcd or pixelshift. When using amaze it often sharpens the amaze diagonals too much.

1 Like

I tend to use dual-demosaic all the time now. I did start looking into whether it was the dual-demsaick :wink: (like that word better) that was the issue but got interrupted before forming a conclusion. Will do some experimentation when I find the time, perhaps I can find a good example image.

1 Like

It’s about time to make a speedup for vng4…

2 Likes

Looking forward to it.

Looking at the backlogs it’s already 10 times faster than 4 years ago:
https://github.com/Beep6581/RawTherapee/issues/2262

https://github.com/Beep6581/RawTherapee/issues/4633

But I will see what I can do to further improve it…

I’ve done some quick tests of capture sharpen oof “dither” now. Is this the place to upload or should i start a thread in the RT forum?

edit: may as well link to filebin from this post Filebin | nofwa4edaqoreb80
Look at the transition from petal to white background above the central diagonal stem. Album view works well in filebin.

Imho better to post in the RT forum

1 Like