MedianBlur2

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Performance: Update with TemporalMedianBlur special cases)
m (Performance: special cases only for 8 bit)
Line 16: Line 16:
 
Unlike the [[MedianBlur|old MedianBlur]], this implementation has constant runtime complexity, meaning that theoretical performance is the same for any radius. Implementation is based on [http://nomis80.org/ctmf.html this paper], but includes some additional optimizations.
 
Unlike the [[MedianBlur|old MedianBlur]], this implementation has constant runtime complexity, meaning that theoretical performance is the same for any radius. Implementation is based on [http://nomis80.org/ctmf.html this paper], but includes some additional optimizations.
  
#When [[SSE2]] is available and radius is 1 or 2, special routines are used. They're a lot faster than the generic one for these radii.
+
#When [[SSE2]] is available and radius is 1 or 2, special routines are used, but only for 8 bit videos. They're a lot faster than the generic one for these radii.
#For 2 < radius < 8, generic approach with 8-bit bin size is used. Using 8-bit bins makes histogram addition/subtraction faster with [[SSE2]] (8 bit videos).
+
#For 2 < radius < 8, generic approach with 8-bit bin size is used. Using 8-bit bins makes histogram addition/subtraction faster with [[SSE2]]
 
#For large radii, 16-bit bins are used, as described in the paper.
 
#For large radii, 16-bit bins are used, as described in the paper.
 
#TemporalMedianBlur is using 32 bit bins
 
#TemporalMedianBlur is using 32 bit bins

Revision as of 13:12, 9 March 2021

Abstract
Author tp7, pinterf
Version v1.0
Download MedianBlur2_v1.0.7z
Category Blurring
License MIT but binaries are GPLv2
Discussion Doom9 Thread


Contents

Description

MedianBlur2 is an implementation of constant time median filter for AviSynth; it includes 2 functions:

  • MedianBlur - a simple median filter similar to the old MedianBlur (function name is still MedianBlur).
  • MedianBlurTemporal - partially implements the old MedianBlurT function but doesn't have MVTools2-related parameters (hence the function name change). If you don't use the mo-comp part of it, you should be able to just change the name used without any other changes.
    Please do note that for temporal-only processing this filter is extremely inefficient (just like the original).


Performance

Unlike the old MedianBlur, this implementation has constant runtime complexity, meaning that theoretical performance is the same for any radius. Implementation is based on this paper, but includes some additional optimizations.

  1. When SSE2 is available and radius is 1 or 2, special routines are used, but only for 8 bit videos. They're a lot faster than the generic one for these radii.
  2. For 2 < radius < 8, generic approach with 8-bit bin size is used. Using 8-bit bins makes histogram addition/subtraction faster with SSE2
  3. For large radii, 16-bit bins are used, as described in the paper.
  4. TemporalMedianBlur is using 32 bit bins
  5. TemporalMedianBlur quick special case for radius=0 and temporal radius 1 or 2

In other words, you can expect huge performance drop when going from 1 to 2, not so huge but still large from 2 to 3 and a noticeable slowdown from 7 to 8. Between them the fps should be constant and it actually might get a bit faster with larger radius. Performance with radius > 2 also depends on the actual frame content. Processing ColorBars() is a lot faster than AddGrainC(10000). It is quite possible that you'll get worse performance for radius = 3 with this plugin compared to the original MedianBlur. All other radii should be (a lot) faster.

High bit depth considerations:

At larger bit depths performance drops because internal histogram tables contain statistical data for 10, 12, 14 and 16 bits precision. Also: higher bit depths need more memory. Unfortunately 32 bit float is faked: float data have to be quantized before processing and is using 16 bit histogram so resulting pixel values are quantized to 16 bits as well. Radii 1 and 2 are special case only for 8 bits as of v1.0.

Requirements


*** vcredist_x86.exe is required for MedianBlur2-x86
*** vcredist_x64.exe is required for MedianBlur2-x64


Syntax and Parameters

MedianBlur

Spatial-only version.

MedianBlur (clip, int "radiusy", int "radiusu", int "radiusv")


clip   =
Input clip must be planar.


int  radiusy = 2
int  radiusu = 2
int  radiusv = 2
Spatial radius; YUV planes are independently processed.
For RGB clips radiusy value is used for all planes.
  • If set to 0 the corresponding plane is copied from the input clip unaltered.
  • If set between -1 and -255 the corresponding plane will be set to -radius. Works only for 8 bits
  • If set to any value less than -255 the corresponding plane will be set to zero.
  • 2 is the default for all planes; maximum value is limited to 127.


If alpha plane is available it will be simply copied.
Planar RGB uses the value of radiusy for all its channels. radius u and radius v are ignored.



MedianBlurTemporal

Spatio-temporal version.


MedianBlurTemporal (clip, int "radiusy", int "radiusu", int "radiusv", int "temporalradius")


clip   =
Input clip must be planar.


int  radiusy = 2
int  radiusu = 2
int  radiusv = 2
Spatial radius; YUV planes are independently processed.
For RGB clips radiusy value is used for all planes.
  • Setting it to 0 will just disable spatial filtering.
  • Setting it to -1 will copy the plane from the input clip.
  • All other values will set the plane to absolute value of radius. Yes, there is no way to set the plane to -1. Works only for 8 bit clips.
  • If set to any value less than -255 the corresponding plane will be set to zero.
  • 2 is the default for all planes; maximum value is limited to 127.


int  temporalradius = 1
Value must be greater than 0; the higher the value the slower it gets.


If alpha plane is available it will be simply copied.
Planar RGB uses the value of radiusy for all its channels. radius u and radius v are ignored.


Examples

  • MedianBlur with default settings:
AviSource("blah.avi")
MedianBlurTemporal(radiusy=2, radiusu=2, radiusv=2)
  • MedianBlurTemporal with default settings:
MedianBlurTemporal(radiusy=2, radiusu=2, radiusv=2, temporalradius=1)  
MedianBlurTemporal(radiusy=0, radiusu=0, radiusv=0, temporalradius=1)  


Changelog

Version      Date            Changes
v1.1 01/30/2021 (pinterf) - Speed: SSE2 and AVX2 for 10+ bits (generic case, MedianBlur) - Speed: SSE2 and AVX2 for TemporalMedianBlur - Speed: Much-much quicker: TemporalMedianBlur special case: temporal radius=1 or 2, spatial radius=0) (C, SSE4.1, AVX2) - Pass frame properties when Avisynth interface>=8 - Debug helper parameter 'opt': integer default -1 <0: autodetect CPU 0: C only (disable SSE2 and AVX2) 1: SSE2 (disable SSE4.1 and AVX2) 2: SSE4 (disable AVX2) 3: AVX2 v1.0 04/02/2020 (pinterf) - add high bitdepth support - add planar RGB support - add version resource to DLL - move to Visual Studio 2019, ClangCL, v141_xp and v142 configurations - project hosted at https://github.com/pinterf/MedianBlur2
v0.94 02/10/2014 (tp7) - MedianBlurTemporal now produces more correct result around the clip borders (first and last frames). - Both functions allow radii less than -255, corresponding plane is set to zero. For compatibility with YAHR and possible other functions. - Compiled with MSVC++12, requires 2012 Redistributable Package (x86 / x64)
v0.93 12/27/2013 - This fixes a huge memory leak in MedianBlurTemp which made it unusable in complex scripts. The function is also renamed to MedianBlurTemporal, which is probably the final name.
v0.92 12/09/2013 - Spatiotemporal median filter called MedianBlurTemp added. Function name is subject to change.
v0.91 12/08/2013 - Plane processors are now independent from each other. It means when you write something like MedianBlur(5,1,1), both chroma planes will now be processed by the optimized routine, rather than the general one as before.
v0.9 12/08/2013 - Initial release.


External Links




Back to External Filters

Personal tools