TColorMask

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(redirect for convenient searching)
 
(tcolormask: add documentation)
Line 1: Line 1:
#REDIRECT [[External_filters#Averaging.2FLayering.2FMasking]]
+
{{FilterCat5|External_filters|Plugins|Plugins_x64|Adjustment_filters|Masking}}
{{FilterCat|External_filters|Adjustment_filters|Masking}}
+
{{Filter3
 +
| {{Author/tp7}}
 +
| v1.2
 +
|[https://github.com/tp7/tcolormask/releases tcolormask-x86.zip // tcolormask-x64.zip]
 +
| Masking
 +
| [http://www.gnu.org/licenses/gpl-2.0.txt GPLv2]
 +
|6=}}
 +
 
 +
== Description ==
 +
[[TColorMask]] This is a port of the great tophf's script [https://pastebin.com/vAa8fyjp t_colormask]. It masks colors but unlike the old ColorKeyMask it works on YV12. The main reason for this plugin is performance. The API and output are not identical, please refer to the Difference section for details.
 +
 
 +
<br>
 +
<br>
 +
 
 +
== Requirements ==
 +
* [x86]: [[AviSynth+]] or [http://sourceforge.net/projects/avisynth2/ AviSynth 2.6]
 +
* [x64]: [[AviSynth+]]
 +
* Supported color formats: [[YV12]], [[YV16]], [[YV24]]
 +
<br>
 +
 
 +
== [[Script variables|Syntax and Parameters]] ==
 +
:{{Template:FuncDef|tcolormask (clip, string "colors, int "tolerance", bool "bt601", bool "gray", int "lutthr", bool "mt")}}
 +
<br>
 +
::{{Par2| |clip| }}
 +
:::Input clip.
 +
<br>
 +
::{{Par2|colors|string|""}}
 +
:::String of colors. Line and block comments are allowed.
 +
<br>
 +
::{{Par2|tolerance|int|10}}
 +
:::Pixel value will pass if its absolute difference with color is less than tolerance (luma) or half the tolerance (chroma).
 +
<br>
 +
::{{Par2|bt601|bool|false}}
 +
:::Use bt601 matrix for conversion of colors.
 +
<br>
 +
::{{Par2|gray|bool|false}}
 +
:::Set chroma of output clip to 128.
 +
<br>
 +
::{{Par2|lutthr|int|9}}
 +
:::If specified more than <code>lutthr</code> colors, LUT will be used instead of direct SIMD computations.
 +
<br>
 +
::{{Par2|mt|bool|true}}
 +
:::Enable multithreading. It actually uses only two threads as any more threading doesn't seem to be useful.
 +
<br>
 +
 
 +
== Difference ==
 +
 
 +
Unlike the old script, this plugin uses a single string to specify all colors and doesn't do any blurring. Wrapper functions are provided for convenience in the bin/tcolormask_wrappers.avs script.
 +
 
 +
Also since we process chroma and luma together to avoid having to merge planes later, output is not identical. Basically it appears a bit less blurred and doesn't contain any non-binary values produced by chroma resizing. This will not be fixed and there's no workaround. You'll most likely be blurring the output clip anyway.
 +
<br>
 +
<br>
 +
== Performance ==
 +
 
 +
This plugin uses direct SIMD computations to do its dirty work. SIMD appears to be faster than LUT for the most common cases, but unfortunately its speed depends on the number of specified colors and at some point it does get slower than LUT. That's why the alternative is also provided. If specified more than lutthr (9 by default) colors, the plugin will use the LUT routine to avoid performance degradation.
 +
 
 +
See performance table on [https://github.com/tp7/tcolormask/tree/master/tcolormask GitHub].
 +
<br>
 +
<br>
 +
== Examples ==
 +
tcolormask with default values, except colors:
 +
AviSource("bah.avi")
 +
tcolormask("$E0C0AB", tolerance=10, bt601=false, gray=false, lutthr=9, mt=true)
 +
<br>
 +
== Changelog ==
 +
Version      Date            Changes<br>
 +
v1.2        2013/11/30      - x64 build added.
 +
                              - Function from tcolormask_wrappers will not work with x64 build of AviSynth+.
 +
v1.1        2013/07/26      - This plugin now only works with AviSynth 2.6 alpha 4. If you need support for older versions, download v1.0.1.
 +
                              - Also, YV16 colorspace is now supported.
 +
v1.0        2013/07/08      - Actually working now.
 +
 
 +
<br>
 +
== External Links ==
 +
*[https://github.com/tp7/tcolormask GitHub] - Source code repository.
 +
<br>
 +
<br>
 +
-----------------------------------------------
 +
'''Back to [[External_filters#Averaging.2FLayering.2FMasking|External Filters]] &larr;'''

Revision as of 17:39, 27 March 2020

Abstract
Author tp7
Version v1.2
Download tcolormask-x86.zip // tcolormask-x64.zip
Category Masking
License GPLv2
Discussion

Contents

Description

TColorMask This is a port of the great tophf's script t_colormask. It masks colors but unlike the old ColorKeyMask it works on YV12. The main reason for this plugin is performance. The API and output are not identical, please refer to the Difference section for details.



Requirements


Syntax and Parameters

tcolormask (clip, string "colors, int "tolerance", bool "bt601", bool "gray", int "lutthr", bool "mt")


clip   =
Input clip.


string  colors = ""
String of colors. Line and block comments are allowed.


int  tolerance = 10
Pixel value will pass if its absolute difference with color is less than tolerance (luma) or half the tolerance (chroma).


bool  bt601 = false
Use bt601 matrix for conversion of colors.


bool  gray = false
Set chroma of output clip to 128.


int  lutthr = 9
If specified more than lutthr colors, LUT will be used instead of direct SIMD computations.


bool  mt = true
Enable multithreading. It actually uses only two threads as any more threading doesn't seem to be useful.


Difference

Unlike the old script, this plugin uses a single string to specify all colors and doesn't do any blurring. Wrapper functions are provided for convenience in the bin/tcolormask_wrappers.avs script.

Also since we process chroma and luma together to avoid having to merge planes later, output is not identical. Basically it appears a bit less blurred and doesn't contain any non-binary values produced by chroma resizing. This will not be fixed and there's no workaround. You'll most likely be blurring the output clip anyway.

Performance

This plugin uses direct SIMD computations to do its dirty work. SIMD appears to be faster than LUT for the most common cases, but unfortunately its speed depends on the number of specified colors and at some point it does get slower than LUT. That's why the alternative is also provided. If specified more than lutthr (9 by default) colors, the plugin will use the LUT routine to avoid performance degradation.

See performance table on GitHub.

Examples

tcolormask with default values, except colors:

AviSource("bah.avi")
tcolormask("$E0C0AB", tolerance=10, bt601=false, gray=false, lutthr=9, mt=true)


Changelog

Version      Date            Changes
v1.2 2013/11/30 - x64 build added. - Function from tcolormask_wrappers will not work with x64 build of AviSynth+. v1.1 2013/07/26 - This plugin now only works with AviSynth 2.6 alpha 4. If you need support for older versions, download v1.0.1. - Also, YV16 colorspace is now supported. v1.0 2013/07/08 - Actually working now.


External Links

  • GitHub - Source code repository.




Back to External Filters

Personal tools