Beep6581 / RawTherapee

A powerful cross-platform raw photo processing program
https://rawtherapee.com
GNU General Public License v3.0
2.77k stars 313 forks source link

Local adjustments - Denoise - Improvments with Non local means #6087

Closed Desmis closed 1 day ago

Desmis commented 3 years ago

Local adjustments – Denoise – improvments with Non-local means

What is « Non Local Means » ?

Here Wikipedia definition : Non-local means is an algorithm in image processing for image denoising Unlike "local mean" filters, which take the mean value of a group of pixels surrounding a target pixel to smooth the image, non-local means filtering takes a mean of all pixels in the image, weighted by how similar these pixels are to the target pixel. This results in much greater post-filtering clarity, and less loss of detail in the image compared with local mean algorithms

In french this algorithm is named « Débruitage par morceaux » ou « Débruitage par patch » which seems to me more explicit.

Where it can be found ?

it seems that this alogorithm is used by DxO

https://www.college-de-france.fr/media/pierre-louis-lions/UPL67973_Jean_Michel_MorelTransparents.pdf

The algorithm used here is close to the one implemented by IPOL in 2014

https://pdfs.semanticscholar.org/a262/269fa4b44b64d750c72fad3887f9d88817ce.pdf

The work of Alberto and Ingo

I had thought of implementing this algorithm, but Alberto @agriggio was faster and made very good improvements with the help of Ingo @heckflosse . Thank you to them for this excellent work

These improvements can be achieved by :

My choices

I made the choice to implement it in « LA », but it is possible to do it for the other denoise modules of Rawtherapee (Noise reduction, Wavelet levels)

I put the code here - branch "laden" https://github.com/Beep6581/RawTherapee/tree/laden

What are the differences with the ART version ? For the code itself few deviations.

I used Lab instead of Yuv, because the base data are in L (Lab)...for this I applied a transformation to make Lab "variable", by default I applied a gamma=3.0 and at the end inverse-gamma=0.3333, but, with the help of Ingo, you can vary the gamma and thus change the distribution of denoise according to solids and textures. . For recall Lab consists of a system with gamma=3.0 and slope=9.03

In «standard and advanced mode » I use "gamma" as above and I enable the 2 hiden variables in ART « max_patch_radius » and « max_search_radius » (advanced) which allows to better adapt the algo to the details of the image, but which resulted in an increase in the processing time for the 2nd.

And of course everything that will allow you to work with a spot...(the Laplacian has already been used for other applications). To note that for "Non-local means" the minimum RT-spot size is 150*150 pixels which nevertheless is very small

How is it implanted here ?

I choose to be able to be used in conjunction with 'Luminance denoise by level' or on its own.

I also chose to be able to use all the particularities of LA : Scope (deltaE), Transitions, Excluding Spot, Mask and 'Recovery based on luminance mask', and of course for one or several RT-Spot or working in « Full image »

The GUI has been modified as a consequence, in particular by changing the selection combobox. It now offers 4 choices :

This modification could lead to difficulties with some pp3 - in this case it is better to clean the cache

« Non local means » is enable when slider « strength » is > 0.

Labels and tooltips have been improved with the participation of Wayne Sutton @waynesutton50 , thanks to him.

What memory usage and processing time ?

For memory, whatever the settings, the consumption is low, thanks again to Alberto and Ingo.

For processing time, here some comparisons (output TIF)

Image 4312 * 2860 (wavelet - conservative)

Full image : wavelet 3000ms – Nlmeans 3000ms

Spot 1200*800 wavelet 260ms – Nlmeans 220ms

Spot 130*100 wavelet 100ms – Nlmeans 20ms

--

Image 6000*4000 (wavelet - conservative)

Full image : wavelet 12000ms – Nlmeans 6000ms

What results ?

Like all noise treatments, the result is quite subjective and depends on individual taste. But personally I find the results very good, especially in conjunction with wavelet and DCT.

Ingo @heckflosse , can you do a check of my code (all is in iplocallab.cc), for example I did not optimize as Alberto did, the optimization of arrays.

Thanks again to Alberto and Ingo for this very interesting improvement. :)

Jacques

heckflosse commented 3 years ago

@Desmis Jacques,

The work of Alberto and Ingo

I had thought of implementing this algorithm, but Alberto @agriggio was faster and made very good improvements with the help of Ingo @heckflosse . Thank you to them for this excellent work

Alberto asked me if I want to have some fun optimizing his implementation. So I did :smiley: Glad you picked it up.

Desmis commented 3 years ago

I just add a slider "gamma". Lower values preserves details and texture, Higher values reinforce denoise.

I also change basic <> standard <> advanced

Jacques

Desmis commented 3 years ago

I just create a PR https://github.com/Beep6581/RawTherapee/pull/6091

Lawrence37 commented 3 years ago

@Desmis Why is the minimum spot size 150x150?

Desmis commented 3 years ago

@Lawrence37 it's just an oversight...when focusing. By the way, on the output part "TIF/JPG", there is no such restriction.

I push a change Thank you Jacques

Lawrence37 commented 3 years ago

FYI the 150x150 also appears here https://github.com/Beep6581/RawTherapee/blob/88a7a7ecc7e739ff8db53fa907b3a474ed7cfb57/rtengine/iplocallab.cc#L10897-L10899 and in the tooltip https://github.com/Beep6581/RawTherapee/blob/88a7a7ecc7e739ff8db53fa907b3a474ed7cfb57/rtdata/languages/default#L2943

Desmis commented 3 years ago

@Lawrence37

Thank you very much... I forgot this 2 "things"....probably it's the age :)

jacques