TNLMeans

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(redirect for convenient searching)
 
(TNLMeans)
Line 1: Line 1:
#REDIRECT [[External_filters#Denoisers]]
+
{{FilterCat4|External_filters|Plugins|Denoisers|Spatial-Temporal Denoisers}}
{{FilterCat|External_filters|Denoisers|}}
+
{{Filter3
 +
|{{Author/tritical}}
 +
|1.0.3
 +
|
 +
3=[http://bengal.missouri.edu/~kes25c/TNLMeansv103.zip TNLMeansv103.zip]
 +
[http://www.sendspace.com/file/6k226c TNLMeans_ICL.7z]
 +
|4=Spatial-Temporal Denoisers
 +
|5=[http://www.gnu.org/licenses/gpl-2.0.txt GPLv2]
 +
|6=[http://forum.doom9.org/showthread.php?t=111344 Doom9 Thread]
 +
}}
 +
 
 +
== Description ==
 +
[[TNLMeans]] is an implementation of the [http://en.wikipedia.org/wiki/Non-local_means NL-means denoising algorithm]. Aside from the original method, [[TNLMeans]] also supports extension into 3D, a faster, block based approach, and a multiscale version.
 +
 
 +
*<tt>TNLMeans_ICL.7z</tt> is an optimized build compiled with ICL10, see [http://forum.doom9.org/showthread.php?t=168090 discussion] for more details.
 +
<br>
 +
 
 +
== Requirements ==
 +
* AviSynth 2.5.8 or [http://sourceforge.net/projects/avisynth2/ greater]
 +
* [[FAQ_different_types_content#How_do_I_recognize_progressive.2C_interlaced.2C_telecined.2C_hybrid_and_blended_content.3F|Progressive]] input only
 +
* Supported color formats: [[YUY2]], [[YV12]]
 +
<br>
 +
==Theory Of Operation:==
 +
 
 +
The NL-means algorithm works in the following manner.  For each pixel in the image define a search window in which to look for similar pixels.  The search window is defined by the parameters Ax and Ay, which set the x-axis radius and y-axis radius.  For each pixel in the window determine a weight based on the similarity of that pixel's gray level neighborhood to the center pixel's gray level neighborhood.  The neighborhood is defined by the Sx and Sy parameters, which set the x-axis radius and y-axis radius.  The similarity between two neighborhoods is measured using gaussian weighted (as a function of distance, the standard deviation is set by the "a" parameter) sum of squared differences. The final weight for a pixel is computed as:
 +
 
 +
exp(-(total_sse_difference/sum_of_gaussian_weights)/(h*h));
 +
 
 +
If the parameter 'sse' is set to false, then sum of absolute differences is used instead of sum of squared differences.  In that case, the final weight for a pixel is computed as:
 +
 
 +
exp(-(total_sad_difference/sum_of_gaussian_weights)/h);
 +
 
 +
Once a weight for each pixel in the window is acquired, the final pixel value is simply the weighted average of all the pixels.  In order for the center pixel to not be too heavily weighted, it is assigned a weight equal to the largest weight given to another pixel in the search window.
 +
 
 +
The block based modification changes the base step (or base window) from 1 pixel to blocks with size Bx and By where Bx and By set the x-axis radius and y-axis radius. The support and search windows still work the same way, but now whole blocks are computed/averaged at once instead of individual pixels.  This modification cuts the computation time down by Bx*2+1)*(By*2+1) times.
 +
 
 +
The 3D extension allows extending the search window into neighbor frames.  The parameter Az sets the temporal (z-axis) radius.  With Az=1 frames n-1 and n+1 would be included.
 +
 
 +
The multiscale version works by running the normal algorithm with Ax/Ay = 2 on the original image, and then running the algorithm again on a downsampled (width/2,height/2) version of the original image with Ax/Ay/Bx/By/Sx/Sy all divided by 2.  The weights from the two scales are then combined to form the final image.  This process can greatly speed up processing for large search windows but sacrifices quality (especially around edges/lines/fine details). The type of downsampling that is used is set by the 'rm' parameter.
 +
 
 +
More information can be found by following the links to papers about NL-means under the TNLMeans portion of http://bengal.missouri.edu/~kes25c/.
 +
<br>
 +
<br>
 +
== [[Script variables|Syntax and Parameters]] ==
 +
:{{Template:FuncDef|TNLMeans (clip, int "Ax", int "Ay", int "Az", int "Sx", int "Sy", int "Bx", int "By", bool "ms", int "rm", float "a", float "h", bool "sse")}}
 +
<br>
 +
::{{Par2| |clip| }}
 +
:::Input clip.
 +
<br>
 +
::{{Par2|Ax|int|4}}
 +
::{{Par2|Ay|int|4}}
 +
::{{Par2|Az|int|0}}
 +
:::These set the x-axis, y-axis, and z-axis radii of the search window.  These must be greater than or equal to 0.  The full window size will be:
 +
::::<code>(Ax*2+1) x (Ay*2+1) x (Az*2+1)</code>
 +
:::Generally, the larger the search window the better the result of the denoising. Of course, the larger the search window the longer the denoising takes.
 +
<br>
 +
::{{Par2|Sx|int|2}}
 +
::{{Par2|Sy|int|2}}
 +
:::These set the x-axis and y-axis radii of the support (similarity neighborhood) window. These must be greater than or equal to 0. A larger similarity window will retain more detail/texture but will also cause less noise removal. Typical values for Sx/Sy are 2 or 3. The full window size will be: <code>(Sx*2+1) x (Sy*2+1)</code>
 +
<br>
 +
::{{Par2|Bx|int|1}}
 +
::{{Par2|By|int|1}}
 +
:::These set the x-axis and y-axis radii of the base window. In the original NL-means algorithm the base was a single pixel (Bx=0 and By=0). Using blocks larger than a single pixel will sacrifice some quality for speed. Note that Sx must be greater than or equal to Bx and Sy must be greater than or equal to By. It is recommended that Sx/Sy be larger than Bx/By.
 +
<br>
 +
::{{Par2|ms|bool|false}}
 +
:::Controls whether or not the multiscale version is used. The multiscale version is faster but lower quality. The larger ax/ay are the greater the speed increase from using the multiscale version will be. If Ax/Ay are less than or equal to 2 then the multiscale version will not give any speed up and will make things slower. The multiscale version requires [[modulo|mod 8]] input (width divisible by 8).
 +
<br>
 +
::{{Par2|rm|int|4}}
 +
:::If ms = true, then rm sets the type of resizing used for downsampling. Possible options:
 +
:::*0 - Point
 +
:::*1 - Bilinear
 +
:::*2 - Bicubic
 +
:::*3 - Lanczos3
 +
:::*4 - Spline16
 +
:::*5 - Spline36
 +
<br>
 +
::{{Par2|a|float|1.0}}
 +
:::Sets the standard deviation of the Gaussian used for weighting the difference calculation used for computing neighborhood similarity. Smaller values will result in less noise removal but will retain more detail/texture.
 +
<br>
 +
::{{Par2|h|float|1.8}}
 +
:::Controls the strength of the filtering (blurring).  Larger values will remove more noise but will also destroy more detail. 'h' should typically be set equal to the standard deviation of the noise in the image when using sse=true and assuming the noise fits the zero mean, Gaussian model.
 +
 
 +
:::*h defaults to 0.5 when sse=false
 +
<br>
 +
::{{Par2|sse|bool|true}}
 +
:::Controls whether sum of squared differences or sum of absolute differences is used when computing neighborhood similarity. sse is slightly slower but retains fine detail/texture better. sad typically works better for cartoons/anime. The 'h' parameter usually needs to be set about 4 times lower when using sad than when using sse.
 +
:::*true - use sse
 +
:::*false - use sad
 +
<br>
 +
 
 +
== Examples ==
 +
TNLMeans with all default settings:
 +
[[AviSource]]("Blah.avi")
 +
TNLMeans(Ax=4, Ay=4, Az=0, Sx=2, Sy=2, Bx=1, By=1, ms=false, rm=4, a=1.0, h=1.8, sse=true)
 +
<br>
 +
== Changelog ==
 +
Version          Date(D/M/Y)      Changes<br>
 +
v1.0.3          08/28/2007      - Removed fast exp() approximation that was used for sse=false. Turns out it was
 +
                                    quite inaccurate and had overflow problems resulting in artifacts.<br>
 +
v1.0.2          07/30/2006      - Fixed a problem with small weights causing artifacts<br>
 +
v1.0.1          06/19/2006      - Fixed a bug that caused a crash when ms=true was used with yuy2 input<br>
 +
v1.0 Final      05/31/2006      - Fixed always creating the downsampled clip unless ms=false was explicitly
 +
                                    specified<br>
 +
v1.0 Beta 2      05/25/2006      + Added multiscale version (parameters ms/rm)
 +
                                  + Added sse parameter
 +
                                  + Optimized non-block based routines by buffering (100% speed increase)
 +
                                  - Removed b parameter
 +
                                  - Fixed a bug in the block based routines that caused some blocks
 +
                                    in the search window not to be tested
 +
                                  - Changed defaults for ax/ay/sx/sy/h<br>
 +
v1.0 Beta 1      05/17/2006      - Initial Release
 +
<br>
 +
== Archived Downloads ==
 +
{| class="wikitable" border="1"; width="600px"
 +
|-
 +
!!width="100px"| Version
 +
!!width="150px"| Download
 +
!!width="150px"| Mirror
 +
|-
 +
!v1.0.3
 +
|[http://bengal.missouri.edu/~kes25c/TNLMeansv103.zip TNLMeansv103.zip]
 +
|[http://web.archive.org/web/20140420182218/http://bengal.missouri.edu/~kes25c/TNLMeansv103.zip TNLMeansv103.zip]
 +
|}
 +
<br>
 +
== External Links ==
 +
*[http://github.com/VFR-maniac/VapourSynth-TNLMeans GitHub] - VapourSynth port of TNLMeans.
 +
<br>
 +
<br>
 +
-----------------------------------------------
 +
'''Back to [[External_filters#Spatio-Temporal_Denoisers| External Filters]] &larr;'''

Revision as of 14:04, 28 November 2015

Abstract
Author tritical
Version 1.0.3
Download TNLMeansv103.zip

TNLMeans_ICL.7z

Category Spatial-Temporal Denoisers
License GPLv2
Discussion Doom9 Thread

Contents

Description

TNLMeans is an implementation of the NL-means denoising algorithm. Aside from the original method, TNLMeans also supports extension into 3D, a faster, block based approach, and a multiscale version.

  • TNLMeans_ICL.7z is an optimized build compiled with ICL10, see discussion for more details.


Requirements


Theory Of Operation:

The NL-means algorithm works in the following manner. For each pixel in the image define a search window in which to look for similar pixels. The search window is defined by the parameters Ax and Ay, which set the x-axis radius and y-axis radius. For each pixel in the window determine a weight based on the similarity of that pixel's gray level neighborhood to the center pixel's gray level neighborhood. The neighborhood is defined by the Sx and Sy parameters, which set the x-axis radius and y-axis radius. The similarity between two neighborhoods is measured using gaussian weighted (as a function of distance, the standard deviation is set by the "a" parameter) sum of squared differences. The final weight for a pixel is computed as:

exp(-(total_sse_difference/sum_of_gaussian_weights)/(h*h));

If the parameter 'sse' is set to false, then sum of absolute differences is used instead of sum of squared differences. In that case, the final weight for a pixel is computed as:

exp(-(total_sad_difference/sum_of_gaussian_weights)/h);

Once a weight for each pixel in the window is acquired, the final pixel value is simply the weighted average of all the pixels. In order for the center pixel to not be too heavily weighted, it is assigned a weight equal to the largest weight given to another pixel in the search window.

The block based modification changes the base step (or base window) from 1 pixel to blocks with size Bx and By where Bx and By set the x-axis radius and y-axis radius. The support and search windows still work the same way, but now whole blocks are computed/averaged at once instead of individual pixels. This modification cuts the computation time down by Bx*2+1)*(By*2+1) times.

The 3D extension allows extending the search window into neighbor frames. The parameter Az sets the temporal (z-axis) radius. With Az=1 frames n-1 and n+1 would be included.

The multiscale version works by running the normal algorithm with Ax/Ay = 2 on the original image, and then running the algorithm again on a downsampled (width/2,height/2) version of the original image with Ax/Ay/Bx/By/Sx/Sy all divided by 2. The weights from the two scales are then combined to form the final image. This process can greatly speed up processing for large search windows but sacrifices quality (especially around edges/lines/fine details). The type of downsampling that is used is set by the 'rm' parameter.

More information can be found by following the links to papers about NL-means under the TNLMeans portion of http://bengal.missouri.edu/~kes25c/.

Syntax and Parameters

TNLMeans (clip, int "Ax", int "Ay", int "Az", int "Sx", int "Sy", int "Bx", int "By", bool "ms", int "rm", float "a", float "h", bool "sse")


clip   =
Input clip.


int  Ax = 4
int  Ay = 4
int  Az = 0
These set the x-axis, y-axis, and z-axis radii of the search window. These must be greater than or equal to 0. The full window size will be:
(Ax*2+1) x (Ay*2+1) x (Az*2+1)
Generally, the larger the search window the better the result of the denoising. Of course, the larger the search window the longer the denoising takes.


int  Sx = 2
int  Sy = 2
These set the x-axis and y-axis radii of the support (similarity neighborhood) window. These must be greater than or equal to 0. A larger similarity window will retain more detail/texture but will also cause less noise removal. Typical values for Sx/Sy are 2 or 3. The full window size will be: (Sx*2+1) x (Sy*2+1)


int  Bx = 1
int  By = 1
These set the x-axis and y-axis radii of the base window. In the original NL-means algorithm the base was a single pixel (Bx=0 and By=0). Using blocks larger than a single pixel will sacrifice some quality for speed. Note that Sx must be greater than or equal to Bx and Sy must be greater than or equal to By. It is recommended that Sx/Sy be larger than Bx/By.


bool  ms = false
Controls whether or not the multiscale version is used. The multiscale version is faster but lower quality. The larger ax/ay are the greater the speed increase from using the multiscale version will be. If Ax/Ay are less than or equal to 2 then the multiscale version will not give any speed up and will make things slower. The multiscale version requires mod 8 input (width divisible by 8).


int  rm = 4
If ms = true, then rm sets the type of resizing used for downsampling. Possible options:
  • 0 - Point
  • 1 - Bilinear
  • 2 - Bicubic
  • 3 - Lanczos3
  • 4 - Spline16
  • 5 - Spline36


float  a = 1.0
Sets the standard deviation of the Gaussian used for weighting the difference calculation used for computing neighborhood similarity. Smaller values will result in less noise removal but will retain more detail/texture.


float  h = 1.8
Controls the strength of the filtering (blurring). Larger values will remove more noise but will also destroy more detail. 'h' should typically be set equal to the standard deviation of the noise in the image when using sse=true and assuming the noise fits the zero mean, Gaussian model.
  • h defaults to 0.5 when sse=false


bool  sse = true
Controls whether sum of squared differences or sum of absolute differences is used when computing neighborhood similarity. sse is slightly slower but retains fine detail/texture better. sad typically works better for cartoons/anime. The 'h' parameter usually needs to be set about 4 times lower when using sad than when using sse.
  • true - use sse
  • false - use sad


Examples

TNLMeans with all default settings:

AviSource("Blah.avi")
TNLMeans(Ax=4, Ay=4, Az=0, Sx=2, Sy=2, Bx=1, By=1, ms=false, rm=4, a=1.0, h=1.8, sse=true)


Changelog

Version          Date(D/M/Y)      Changes
v1.0.3 08/28/2007 - Removed fast exp() approximation that was used for sse=false. Turns out it was quite inaccurate and had overflow problems resulting in artifacts.
v1.0.2 07/30/2006 - Fixed a problem with small weights causing artifacts
v1.0.1 06/19/2006 - Fixed a bug that caused a crash when ms=true was used with yuy2 input
v1.0 Final 05/31/2006 - Fixed always creating the downsampled clip unless ms=false was explicitly specified
v1.0 Beta 2 05/25/2006 + Added multiscale version (parameters ms/rm) + Added sse parameter + Optimized non-block based routines by buffering (100% speed increase) - Removed b parameter - Fixed a bug in the block based routines that caused some blocks in the search window not to be tested - Changed defaults for ax/ay/sx/sy/h
v1.0 Beta 1 05/17/2006 - Initial Release


Archived Downloads

Version Download Mirror
v1.0.3 TNLMeansv103.zip TNLMeansv103.zip


External Links

  • GitHub - VapourSynth port of TNLMeans.




Back to External Filters

Personal tools