darktable-org / darktable

darktable is an open source photography workflow application and raw developer
https://www.darktable.org
GNU General Public License v3.0
9.52k stars 1.12k forks source link

Sharpen module based on wavelet decomposition #16161

Open Pat-sz opened 7 months ago

Pat-sz commented 7 months ago

Is your feature request related to an issue? Please describe. I use the high pass module to improve the sharpness of my photo, but this module is not optimized.

Describe the solution you want When I use the Retouch module, I often use wavelet decomposition to correct defects in my photo. When the "show single decomposition" option is checked, the screen displays a sharper image with areas of contrast in the focus area. I think this module needs to use a "soft light" blending mode to improve the contrast and sense of sharpness in the focus area. In this screenshot, on the left is the high pass result, and on the right is the wavelet decomposition. As we can see, the wavelet decomposition presents a finer contrast in the focus zone and not in the blur zone. Screenshot_20240121_135626 I think it needs some options on the proposal module, like one to improve the contrast of the decomposition.

ralfbrown commented 7 months ago

The "contrast equalizer" module does sharpening (as well as denoising) based on wavelet decomposition.

Using the "highpass" module in overlay mode for sharpening gives you a result that is mathematically nearly identical to the unsharp mask algorithm, which is what the "sharpen" module uses. The "sharpness" (top) slider in "highpass" controls the fine-ness of the detected edges in the same way as the "radius" (top) slider in "sharpen".

If you want to increase the contrast of the displayed wavelet layer in Retouch, adjust the white and black points on the gray ramp at the bottom of the module. (This only affects the display.)

Donatzsky commented 7 months ago

There's also diffuse or sharpen which is wavelet based.

Pat-sz commented 7 months ago

@ralfbrown Indeed, if the "contrast equalizer" does what I think it does, then it would be useful if there was an option to see, like in Retouch, how the contrast is calculated to finely adjust each curve. This is just an observation from my use of Darktable (I think you could consider me an advanced user). I find that with some images, in the Retouch module, the wavelet decomposition image is sharper than any results I can get with other modules that I have used to improve local contrast, finer and more precise. I have the impression that I am able to display, in this view, a best contrast and a feeling of sharpness in areas of the image, where other modules only increase the noise.

ralfbrown commented 7 months ago

That's an illusion caused by the fact that the wavelets display in Retouch is showing you specifically one scale, while the final result (in all of the modules using wavelets) is produced by adding together all of the scales. Plus wavelet scales contain both positive and negative values due to how they are generated. Finally, Retouch boosts the contrast so that you can see them at all, since the actual values are very small, especially at the finest levels (notice how close together the white and black points are after clicking the auto-levels button).

The basic operation of the wavelet algorithms that darktable uses is to apply a blurring operation to the input, then subtract the blurred version from the input go generate one wavelet scale. Repeat using double the blurring radius on the already-blurred version and subtract again to generate the next wavelet scale (e.g. instead of looking at the immediate neighbor pixels, you look at those two away, then four away, etc.).

You recover the original image by simply adding together all of the wavelets scales and the residual. You increase contrast at a specific level of detail by multiplying the values in that wavelet scale by a factor greater than 1.0 before adding them back together. You do denoising by shifting all values in a wavelet scale toward zero by a fixed amount (using zero as the result if the sign changes).

Pat-sz commented 7 months ago

@ralfbrown Thank you for your explanation, it's clear to me now. Therefore, perhaps using the contrast equalizer can be easier with an option like in the Retouch module to visualize the wavelet result. For me, it is easier to understand how a module works if I can see the result (Contrast or blur) before applying it to the photo.

elstoc commented 7 months ago

This has been suggested before: https://github.com/darktable-org/darktable/issues/5855

europlatus commented 6 months ago

@elstoc I notice that the previous issue was 4 years ago and the reason the issue was closed was because of pipeline design and unrealistic runtimes. I wonder if changes over the last few versions have helped make this more of a possibility?

Short of implementing a specific wavelet decompose mask (which would be the ideal solution), I was also thinking along the same lines as you of some kind of "hacked" difference blending mode that boosted the brightness and/or used grayscale instead of inverted colours. If a standard brightness can't be set, could a fulcrum slider be added, like other blending modes?

I was specifically thinking how much something like this would help for Diffuse or Sharpen, but as people have been wanting something similar for Contrast Equalizer and the Sharpen modules, maybe if such a blend mode could be implemented, it could be used by any module.

IMO Diffuse or Sharpen sorely needs such a visualization to help with setting the central radius and radius span parameters.

github-actions[bot] commented 4 months ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.