Bug 174177

Summary: Proposal for implementing smart unsharp masking
Product: [Applications] digikam Reporter: Dik Takken <kde>
Component: Plugin-Editor-SharpenAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: caulier.gilles
Priority: NOR    
Version: 0.9.4   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In: 8.0.0

Description Dik Takken 2008-11-03 16:52:40 UTC
Version:           0.9.4 (using KDE 3.5.10)
OS:                Linux
Installed from:    Gentoo Packages

There are two problems with plain unsharp masking:

* It amplifies noise
* It destroys image detail due to clipping of highlights and shadows

Both problems can be fixed by 'smart unshap masking'. 

The noise problem can be solved by masking the whole image, except for the edges. In the GIMP:

* Duplicate layer
* Use 'Edge' filter to find the edges in the image
* Convert to grayscale
* Apply gaussian blur to make smooth edges (slightly, 5 pixels or so)
* Apply levels to increase the contrast, this will influence noise suppression

Now you have a mask that you can use to combine the original image with the unsharp masked one. Only the areas that feature lots of detail will be unsharp masked.

The clipping problem can be solved by masking the highlights and shadows in the image. In the GIMP:

* Duplicate layer
* Convert to grayscale
* Use the Curves tool to make the shadows and highlights turn out black, the middle tones should be white. There should be a steep but smooth transition in between. The shadow and highlight thresholds depend on the image and the strength of unsharp masking.

There is another technique that cannot be done in the GIMP, but it could be implemented in DigiKam. It might yield better results and might be simpler to implement:

* Apply normal unsharp masking
* Create a mask from all pixels that are clipped after unsharp masking
* Blur the mask slightly, gives smooth transitions
* Now re-do the unsharp masking, using the mask to prevent clipping.

Currently, I apply the above two GIMP procedures manually. When I need 16-bit support, I apply them using ImageMagick. It would be great if DigiKam could add a 'noise suppression' and a 'protect shadows/highligts' option to its unsharp masking implementation, so these techniques can be applied automatically.
Comment 1 caulier.gilles 2023-04-06 15:42:48 UTC
The Image Editor GMIC-Qt etails/Unsharp Mask sounds like a good alternative which implements a better algorithms working on more colore space with plenty of highlight/darkness adjustements.

https://i.imgur.com/85ILMZP.png

Gilles Caulier