# MedianBlur2

(→Changelog: update to v1.0) |
(v1.0 minor touchup) |
||

Line 1: | Line 1: | ||

{{FilterCat5|External_filters|Plugins|Plugins_x64|Adjustment_filters|Blurring}} | {{FilterCat5|External_filters|Plugins|Plugins_x64|Adjustment_filters|Blurring}} | ||

{{Filter3 | {{Filter3 | ||

− | | {{Author/tp7}}, | + | | {{Author/tp7}}, {{Author/pinterf}} |

− | | v1.0 | + | | v1.0 |

− | | [https://github.com/pinterf/MedianBlur2/releases | + | | [https://github.com/pinterf/MedianBlur2/releases MedianBlur2_v1.0.7z] |

| Blurring | | Blurring | ||

| [https://opensource.org/licenses/MIT MIT] but binaries are [https://www.gnu.org/licenses/gpl-2.0.txt GPLv2] | | [https://opensource.org/licenses/MIT MIT] but binaries are [https://www.gnu.org/licenses/gpl-2.0.txt GPLv2] | ||

Line 23: | Line 23: | ||

<br> | <br> | ||

<br> | <br> | ||

− | High bit depth considerations: | + | '''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. | 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. | ||

Line 29: | Line 29: | ||

Radii 1 and 2 are special case only for 8 bits as of v1.0. | Radii 1 and 2 are special case only for 8 bits as of v1.0. | ||

<br> | <br> | ||

− | + | <br> | |

== Requirements == | == Requirements == | ||

− | * [https://sourceforge.net/projects/avisynth2/ AviSynth 2.6 | + | * [x86]: [[AviSynth+]] or [https://sourceforge.net/projects/avisynth2/ AviSynth 2.6] |

− | * x64 | + | * [x64]: [[AviSynth+]] |

− | * Supported color formats: | + | * Supported color formats: [[Y8]], [[YV12]], [[YV16]], [[YV24]], [[YV411]] |

+ | ** AviSynth+: All planar formats (8/10/12/14/16/32bit, Y/YUV/RGB with or without alpha) are supported. | ||

<br> | <br> | ||

− | * | + | * [https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads Microsoft Visual C++ 2019 Redistributable Package (x86 / x64)] |

− | + | :<span style="color:red">***</span> <tt>vcredist_x86.exe</tt> is required for <tt>MedianBlur2-x86</tt> | |

− | + | :<span style="color:red">***</span> <tt>vcredist_x64.exe</tt> is required for <tt>MedianBlur2-x64</tt> | |

− | + | ||

− | + | ||

− | + | ||

<br> | <br> | ||

Line 56: | Line 54: | ||

::{{Par2|radiusv|int|2}} | ::{{Par2|radiusv|int|2}} | ||

:::Spatial radius; YUV planes are independently processed. | :::Spatial radius; YUV planes are independently processed. | ||

− | ::: | + | :::For RGB clips <code>radiusy</code> 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. | |

<br> | <br> | ||

− | + | ::If alpha plane is available it will be simply copied. | |

− | If alpha plane is available it will be simply copied. | + | ::Planar RGB uses the value of <code>radiusy</code> for all its channels. <code>radius</code> u and <code>radius</code> v are ignored. |

− | Planar RGB | + | |

<br> | <br> | ||

Line 84: | Line 81: | ||

:::Spatial radius; YUV planes are independently processed. | :::Spatial radius; YUV planes are independently processed. | ||

− | ::: | + | :::For RGB clips <code>radiusy</code> 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. | ||

<br> | <br> | ||

Line 95: | Line 93: | ||

:::Value must be greater than 0; the higher the value the slower it gets. | :::Value must be greater than 0; the higher the value the slower it gets. | ||

<br> | <br> | ||

− | + | ::If alpha plane is available it will be simply copied. | |

− | + | ::Planar RGB uses the value of <code>radiusy</code> for all its channels. <code>radius</code> u and <code>radius</code> v are ignored. | |

− | If alpha plane is available it will be simply copied. | + | |

− | Planar RGB | + | |

<br> | <br> | ||

Line 121: | Line 117: | ||

- add version resource to DLL | - add version resource to DLL | ||

- move to Visual Studio 2019, ClangCL, v141_xp and v142 configurations | - move to Visual Studio 2019, ClangCL, v141_xp and v142 configurations | ||

− | - project hosted at https://github.com/pinterf/MedianBlur2 | + | - project hosted at https://github.com/pinterf/MedianBlur2<br> |

v0.94 02/10/2014 (tp7) | v0.94 02/10/2014 (tp7) | ||

- MedianBlurTemporal now produces more correct result around the clip borders (first and last frames). | - 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. | - Both functions allow radii less than -255, corresponding plane is set to zero. | ||

− | For compatibility with [[YAHR]] and possible other functions.<br> | + | For compatibility with [[YAHR]] and possible other functions. |

+ | - Compiled with MSVC++12, requires 2012 Redistributable Package (x86 / x64)<br> | ||

v0.93 12/27/2013 - This fixes a huge memory leak in MedianBlurTemp which made it unusable in complex scripts. | 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.<br> | The function is also renamed to MedianBlurTemporal, which is probably the final name.<br> | ||

Line 133: | Line 130: | ||

v0.9 12/08/2013 - Initial release. | v0.9 12/08/2013 - Initial release. | ||

<br> | <br> | ||

− | |||

− | |||

== External Links == | == External Links == | ||

*[https://forum.doom9.org/showthread.php?t=169832 Doom9 Forum] - MedianBlur2 discussion, more information [http://forum.doom9.org/showthread.php?p=1656988#post1656988 here]. | *[https://forum.doom9.org/showthread.php?t=169832 Doom9 Forum] - MedianBlur2 discussion, more information [http://forum.doom9.org/showthread.php?p=1656988#post1656988 here]. | ||

*[http://nomis80.org/ctmf.html Median Filtering in Constant Time] | [https://web.archive.org/web/20141115173428/http://nomis80.org/ctmf.html Mirror] | *[http://nomis80.org/ctmf.html Median Filtering in Constant Time] | [https://web.archive.org/web/20141115173428/http://nomis80.org/ctmf.html Mirror] | ||

+ | *[https://github.com/tp7/MedianBlur2 GitHub] - Source code repository (original) | ||

+ | *[https://github.com/pinterf/MedianBlur2 GitHub] - Source code repository (update) | ||

<br> | <br> | ||

<br> | <br> | ||

----------------------------------------------- | ----------------------------------------------- | ||

'''Back to [[External_filters#Blurring|External Filters]] ←''' | '''Back to [[External_filters#Blurring|External Filters]] ←''' |

## Revision as of 01:09, 3 June 2020

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.

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

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

- [x86]: AviSynth+ or AviSynth 2.6
- [x64]: AviSynth+
- Supported color formats: Y8, YV12, YV16, YV24, YV411
- AviSynth+: All planar formats (8/10/12/14/16/32bit, Y/YUV/RGB with or without alpha) are supported.

- ***
`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)

- Same as Clense() but much slower:

MedianBlurTemporal(radiusy=0, radiusu=0, radiusv=0, temporalradius=1)

## Changelog

Version Date Changes

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

- Doom9 Forum - MedianBlur2 discussion, more information here.
- Median Filtering in Constant Time | Mirror
- GitHub - Source code repository (original)
- GitHub - Source code repository (update)

**Back to External Filters ←**