                                    TNLMeans for Avisynth v2.5.x
                                    v1.0.3  (28 August 2007)
                                    by tritical
																		mod. 64 bit version by Groucho2004


INFO:


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

   Syntax =>

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



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/.



PARAMETERS:


   Ax, Ay, Az -

      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.

      Default:  Ax = 4 (int)
                Ay = 4 (int)
                Az = 0 (int)


   Sx, Sy -

      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)

      Default:  Sx = 2 (int)
                Sy = 2 (int)


   BX, By -

      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.

      Default:  Bx = 1 (int)
                By = 1 (int)


   a -

      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.

      Default:  1.0 (float)


   h -

      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.

      Default:  if sse = true  - 1.8 (float)
                if sse = false - 0.5 (float)


   sse -

      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

      Default:  true (bool)


