RedAverage

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(redirect for convenient searching)
 
(RedAverage: add documentation)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
#REDIRECT [[External_filters#Averaging.2FLayering.2FMasking]]
+
{{FilterCat5|External_filters|Plugins|Adjustment_filters|Averaging|Deep_color_tools}}
{{FilterCat|External_filters|Adjustment_filters|Averaging}}
+
{{Filter3
 +
| redfordxx
 +
| v1.4.3
 +
|[http://chaosking.de/repo/avsfilters/Unclassified/RedAverage___%281.4.3_-_2011-12-02%29.7z RedAverage___(1.4.3_-_2011-12-02).7z]
 +
| Averaging
 +
| GPL
 +
|6=[https://forum.doom9.org/showthread.php?t=163018 Doom9 Thread]}}
 +
<br>
 +
 
 +
== Description ==
 +
Averaging plugin, includes these filters:
 +
*RAverageM - masked average
 +
*RAverageW - weighted average
 +
*RMerge - yet another merge filter
 +
<br>
 +
 
 +
== Requirements ==
 +
* [x86] [[AviSynth+]] or [https://sourceforge.net/projects/avisynth2/ AviSynth 2.6.0]
 +
* Supported color formats: [[YV12]]
 +
<br>
 +
 
 +
== [[Script variables|Syntax and Parameters]] ==
 +
 
 +
===RAverageM ===
 +
Computes value of masked average of clips: <code>result=c1*m1+c2*m2+...cn*mn+bias</code>
 +
<br>
 +
<br>
 +
:{{Template:FuncDef|RAverageM (clip1, mask1, clip2, mask2, ... clipn,maskn, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out")}}
 +
<br>
 +
::{{Par2| |clip| }}
 +
:::Input clips; clip followed by a mask clip. An even number of clips is required.
 +
<br>
 +
::{{Par2|bias|float|0.0}}
 +
:::Number which is added to finally computed value (just fyi: <code>bias=-0.5</code> kills rounding the result).
 +
<br>
 +
::{{Par2|y|int|3}}
 +
::{{Par2|u|int|3}}
 +
::{{Par2|v|int|3}}
 +
:::Plane processing. By default, all planes are processed.
 +
:::*3 : process plane
 +
:::*other numbers disable processing
 +
<br>
 +
::{{Par2|sse|int|-1}}
 +
:::Limits the processor capabilities.
 +
:::*-1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
 +
:::*0 = no asm, which is veeeeryyyy sloooow.
 +
<br>
 +
::{{Par2|lsb_in|bool|false}}
 +
:::If true, [[Stack16|16bit stacked]] input is expected.
 +
<br>
 +
::{{Par2|lsb_out|bool|false}}
 +
:::If true, [[Stack16|16bit stacked]] output is produced.
 +
<br>
 +
===RAverageW ===
 +
Computes value of weighted average of clips: <code>result=c1*w1+c2*w2+...cn*wn+bias</code>
 +
<br>
 +
<br>
 +
:{{Template:FuncDef|RAverageW (clip1, weight1, clip2, weight2, ... clipn, weightn, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode", int "errlevel", bool "silent")}}
 +
<br>
 +
::{{Par2| |clip| }}
 +
::{{Par2| |float| }}
 +
:::Input clips and weights; clip followed by a weight. An even number of clips and weights is required.
 +
<br>
 +
::{{Par2|bias|float|0.0}}
 +
:::Number which is added to finally computed value (just fyi: <code>bias=-0.5</code> kills rounding the result).
 +
<br>
 +
::{{Par2|y|int|3}}
 +
::{{Par2|u|int|3}}
 +
::{{Par2|v|int|3}}
 +
:::Plane processing. By default, all planes are processed.
 +
:::*3 : process plane
 +
:::*other numbers disable processing
 +
<br>
 +
::{{Par2|sse|int|-1}}
 +
:::Limits the processor capabilities.
 +
:::*-1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
 +
:::*0 = no asm, which is veeeeryyyy sloooow.
 +
<br>
 +
::{{Par2|lsb_in|bool|false}}
 +
:::If true, [[Stack16|16bit stacked]] input is expected.
 +
<br>
 +
::{{Par2|lsb_out|bool|false}}
 +
:::If true, [[Stack16|16bit stacked]] output is produced.
 +
<br>
 +
::{{Par2|mode|int|-1}}
 +
:::Bitwise 4, 8 for enabling method 4, 8. 0 results in unoptimized C++.
 +
:::*<code>mode=8</code> : requires SSE2, has higher precision than 4 but depending on hardware, probably will be slower
 +
:::*<code>mode=4</code> : requires SSSE3, is faster, however has certain limitations in precision (if you don't have silent true, you will be warned) (8bit in only atm, 8 or 16 out).
 +
::::Basically method 4 is fully precise, when weights are nice power-of-two-numbers, specifically: w_i=a_i*2^k (a_i are integers and k is integer, all signed... Moreover sum[max(a_i,0)]<128 and sum[min(a_i,0)]>-128
 +
::::...in other words, weights must be scalable to signed byte;-)
 +
:::*<code>mode=0</code> : plain C++, slow, fully precise (I think) and supports fully 8 & 16bit clips in and out.
 +
:::Concerning 16bit support and conversion when the in and out have different bitdepth, the values are relative to full scale. That introduces multiplication or division by 256 in case of change of bitdepth. So: 8bitvalue*weight*256=16bitvalue.
 +
 
 +
<br>
 +
::{{Par2|errlevel|int|0}}
 +
:::Sets the maximum rounding error you are willing to accept as a tradeoff to faster method.
 +
<br>
 +
::{{Par2|silent|bool|false}}
 +
::: If true, certain error messages (mostly about rounding error) are suppressed.
 +
<br>
 +
===RMerge===
 +
Merges two clips based on mask, as expected. However, there are some new things. First, again, 16bit support, and 2 different modes.<br>
 +
<br>
 +
<br>
 +
:{{Template:FuncDef|RMerge(clip1, clip2, mask clip, int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode")}}
 +
:{{Template:FuncDef|RMerge(clip1, clip2, mask clip, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode")}}
 +
<br>
 +
::{{Par2| |clip| }}
 +
::{{Par2| |clip| }}
 +
::{{Par2| |clip| }}
 +
:::Input clips; 2 clips to be merged followed by a mask clip.
 +
<br>
 +
::{{Par2|bias|float|0.0}}
 +
:::Number which is added to finally computed value (just fyi: <code>bias=-0.5</code> kills rounding the result).
 +
<br>
 +
::{{Par2|y|int|3}}
 +
::{{Par2|u|int|3}}
 +
::{{Par2|v|int|3}}
 +
:::Plane processing:
 +
:::* 1 : do nothing (garbage)
 +
:::* 2 : copy plane from first clip
 +
:::* 3 : process
 +
:::* 4 : copy plane from second clip
 +
<br>
 +
::{{Par2|sse|int|-1}}
 +
:::Limits the processor capabilities.
 +
:::*-1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
 +
:::*0 = no asm, which is veeeeryyyy sloooow.
 +
:::*Only lsb_in=lsb_out=false and mode=255 are SSSE3 optimized. Anything else goes plain C++.
 +
<br>
 +
::{{Par2|lsb_in|bool|false}}
 +
:::If true, [[Stack16|16bit stacked]] input is expected.
 +
<br>
 +
::{{Par2|lsb_out|bool|false}}
 +
:::If true, [[Stack16|16bit stacked]] output is produced.
 +
<br>
 +
::{{Par2|mode|int|255}}
 +
:::Then there are two modes in case 8bit input which decide, whether the mask is applied slightly differently to correct the problem of incomplete range of the mask:
 +
:::*mode=255 ...this is standard merge formula: r=c1*(256-m)+c2*m
 +
:::*mode=256 ...this is adjusted merge formula: r=c1*(256-n)+c2*n where n= ( m<=128 ? m : m+(m-128)/128 )
 +
:::*lsb_in=true ...this is 16bit merge formula: r=c1*(65536-m)+c2*m
 +
:::*Then, r is scaled and rounded to results r8 or r16, depending on output bitdepth.
 +
:::*The goal of mode 256 is to allow merge values in full range and if m=255, then r8=c2 ... (...and not r8=(c1+c2*255+128)/256 like usually and in mode 255)
 +
<br>
 +
 
 +
== Examples ==
 +
TODO
 +
<br>
 +
<br>
 +
== Changelog ==
 +
Version      Date            Changes<br>
 +
v1.4.3      2011/12/02      - serious bugfix, thanx to Bloax for pointing out
 +
v1.4.2                      - bugfix of RMerge SSSE3, switched clips in RMerge to match the mt_merge formula, minor improvements
 +
v1.4.1                      - SSSE3 optimization of RMerge in 8bit
 +
v1.4.0                      - introduction of of new filter RMerge
 +
v1.3.1                      - full 16bit support for RAverageW mode 8 (SSE2) and minor speed improvements
 +
v1.3.9                      - added 16bit support for RAverageW, however not always SIMD optimized. Multiple algorithms available,
 +
                                different in speed and precision. Thorough estimation of rounding error at the beginning added,
 +
                                so that the most suitable algo is chosen. Ugly source included.
 +
v1.3.5      2011/11/20      - something I am not afraid to publish, but I am afraid to publish the messy src
 +
<br>
 +
== Archived Downloads ==
 +
{| class="wikitable" border="1"; width="600px"
 +
|-
 +
!!width="100px"| Version
 +
!!width="150px"| Download
 +
!!width="150px"| Mirror
 +
|-
 +
!v1.4.3
 +
|[http://chaosking.de/repo/avsfilters/Unclassified/RedAverage___%281.4.3_-_2011-12-02%29.7z RedAverage___(1.4.3_-_2011-12-02).7z]
 +
|[https://web.archive.org/web/20170620012958/http://chaosking.de/repo/avsfilters/Unclassified/RedAverage___%281.4.3_-_2011-12-02%29.7z RedAverage___(1.4.3_-_2011-12-02).7z]
 +
|}
 +
<br>
 +
 
 +
== External Links ==
 +
<br>
 +
<br>
 +
-----------------------------------------------
 +
'''Back to [[External_filters#Averaging.2FLayering.2FMasking|External Filters]] &larr;'''
 +
-----------------------------------------------

Latest revision as of 04:12, 30 May 2020

Abstract
Author redfordxx
Version v1.4.3
Download RedAverage___(1.4.3_-_2011-12-02).7z
Category Averaging
License GPL
Discussion Doom9 Thread


Contents

[edit] Description

Averaging plugin, includes these filters:

  • RAverageM - masked average
  • RAverageW - weighted average
  • RMerge - yet another merge filter


[edit] Requirements


[edit] Syntax and Parameters

[edit] RAverageM

Computes value of masked average of clips: result=c1*m1+c2*m2+...cn*mn+bias

RAverageM (clip1, mask1, clip2, mask2, ... clipn,maskn, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out")


clip   =
Input clips; clip followed by a mask clip. An even number of clips is required.


float  bias = 0.0
Number which is added to finally computed value (just fyi: bias=-0.5 kills rounding the result).


int  y = 3
int  u = 3
int  v = 3
Plane processing. By default, all planes are processed.
  • 3 : process plane
  • other numbers disable processing


int  sse = -1
Limits the processor capabilities.
  • -1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
  • 0 = no asm, which is veeeeryyyy sloooow.


bool  lsb_in = false
If true, 16bit stacked input is expected.


bool  lsb_out = false
If true, 16bit stacked output is produced.


[edit] RAverageW

Computes value of weighted average of clips: result=c1*w1+c2*w2+...cn*wn+bias

RAverageW (clip1, weight1, clip2, weight2, ... clipn, weightn, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode", int "errlevel", bool "silent")


clip   =
float   =
Input clips and weights; clip followed by a weight. An even number of clips and weights is required.


float  bias = 0.0
Number which is added to finally computed value (just fyi: bias=-0.5 kills rounding the result).


int  y = 3
int  u = 3
int  v = 3
Plane processing. By default, all planes are processed.
  • 3 : process plane
  • other numbers disable processing


int  sse = -1
Limits the processor capabilities.
  • -1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
  • 0 = no asm, which is veeeeryyyy sloooow.


bool  lsb_in = false
If true, 16bit stacked input is expected.


bool  lsb_out = false
If true, 16bit stacked output is produced.


int  mode = -1
Bitwise 4, 8 for enabling method 4, 8. 0 results in unoptimized C++.
  • mode=8 : requires SSE2, has higher precision than 4 but depending on hardware, probably will be slower
  • mode=4 : requires SSSE3, is faster, however has certain limitations in precision (if you don't have silent true, you will be warned) (8bit in only atm, 8 or 16 out).
Basically method 4 is fully precise, when weights are nice power-of-two-numbers, specifically: w_i=a_i*2^k (a_i are integers and k is integer, all signed... Moreover sum[max(a_i,0)]<128 and sum[min(a_i,0)]>-128
...in other words, weights must be scalable to signed byte;-)
  • mode=0 : plain C++, slow, fully precise (I think) and supports fully 8 & 16bit clips in and out.
Concerning 16bit support and conversion when the in and out have different bitdepth, the values are relative to full scale. That introduces multiplication or division by 256 in case of change of bitdepth. So: 8bitvalue*weight*256=16bitvalue.


int  errlevel = 0
Sets the maximum rounding error you are willing to accept as a tradeoff to faster method.


bool  silent = false
If true, certain error messages (mostly about rounding error) are suppressed.


[edit] RMerge

Merges two clips based on mask, as expected. However, there are some new things. First, again, 16bit support, and 2 different modes.


RMerge(clip1, clip2, mask clip, int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode")
RMerge(clip1, clip2, mask clip, float "bias", int "y", int "u", int "v", int "sse", bool "lsb_in", bool "lsb_out", int "mode")


clip   =
clip   =
clip   =
Input clips; 2 clips to be merged followed by a mask clip.


float  bias = 0.0
Number which is added to finally computed value (just fyi: bias=-0.5 kills rounding the result).


int  y = 3
int  u = 3
int  v = 3
Plane processing:
  • 1 : do nothing (garbage)
  • 2 : copy plane from first clip
  • 3 : process
  • 4 : copy plane from second clip


int  sse = -1
Limits the processor capabilities.
  • -1 = use all (bitwise...16,8,4=SSE4.1,SSSE3,SSE2).
  • 0 = no asm, which is veeeeryyyy sloooow.
  • Only lsb_in=lsb_out=false and mode=255 are SSSE3 optimized. Anything else goes plain C++.


bool  lsb_in = false
If true, 16bit stacked input is expected.


bool  lsb_out = false
If true, 16bit stacked output is produced.


int  mode = 255
Then there are two modes in case 8bit input which decide, whether the mask is applied slightly differently to correct the problem of incomplete range of the mask:
  • mode=255 ...this is standard merge formula: r=c1*(256-m)+c2*m
  • mode=256 ...this is adjusted merge formula: r=c1*(256-n)+c2*n where n= ( m<=128 ? m : m+(m-128)/128 )
  • lsb_in=true ...this is 16bit merge formula: r=c1*(65536-m)+c2*m
  • Then, r is scaled and rounded to results r8 or r16, depending on output bitdepth.
  • The goal of mode 256 is to allow merge values in full range and if m=255, then r8=c2 ... (...and not r8=(c1+c2*255+128)/256 like usually and in mode 255)


[edit] Examples

TODO

[edit] Changelog

Version      Date            Changes
v1.4.3 2011/12/02 - serious bugfix, thanx to Bloax for pointing out v1.4.2 - bugfix of RMerge SSSE3, switched clips in RMerge to match the mt_merge formula, minor improvements v1.4.1 - SSSE3 optimization of RMerge in 8bit v1.4.0 - introduction of of new filter RMerge v1.3.1 - full 16bit support for RAverageW mode 8 (SSE2) and minor speed improvements v1.3.9 - added 16bit support for RAverageW, however not always SIMD optimized. Multiple algorithms available, different in speed and precision. Thorough estimation of rounding error at the beginning added, so that the most suitable algo is chosen. Ugly source included. v1.3.5 2011/11/20 - something I am not afraid to publish, but I am afraid to publish the messy src


[edit] Archived Downloads

Version Download Mirror
v1.4.3 RedAverage___(1.4.3_-_2011-12-02).7z RedAverage___(1.4.3_-_2011-12-02).7z


[edit] External Links




Back to External Filters


Personal tools