MaskTools2

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (add link to developer's page)
m (add link to home page)
Line 240: Line 240:
  
 
== Links ==
 
== Links ==
 +
 +
[http://manao4.free.fr/mt_masktools.html MaskTools2 Homepage]
  
 
The latest version can always be downloaded from [http://manao4.free.fr/?M=D manao4.free.fr] or [http://forum.doom9.org/showthread.php?t=98985 its Doom9 thread].
 
The latest version can always be downloaded from [http://manao4.free.fr/?M=D manao4.free.fr] or [http://forum.doom9.org/showthread.php?t=98985 its Doom9 thread].
  
 
[[Category:Plugins]]
 
[[Category:Plugins]]

Revision as of 03:09, 26 October 2013

Abstract
Author Kurosu, Manao, mg262
Version 2.0a48
Download manao4.free.fr
Category Support filters
Requirements
  • Avisynth 2.56+
  • YV12
License GPL
Discussion

Contents

Introduction

MaskTools2 contain a set of filters designed to create, manipulate and use masks. Masks, in video processing, are a way to give a relative importance to each pixel. You can, for example, create a mask that selects only the green parts of the video, and then replace these parts with another video.

To give the most control over the handling of masks, the filters will use the fact that each luma and chroma planes can be uncorrelated. That mean that a single video will always be considered by the filters as 3 independant planes. That applies for masks as well, which means that a mask clip will in fact contain 3 masks, one for each plane.

The filters have a set of common parameters, that mainly concern what processing to do on each plane. They all work only in YV12 (though with Avisynth 2.6, support for all planar formats will be available).

Common parameters

As said previously, all the filters - except the helpers - share a common set of parameters. These parameters are used to tell what processing to do on each plane / channel, and what area of the video to process.

  • int "offx" (0), int "offy" (0)
offx and offy are the top left coordinates of the box where the actual processing shall occur. Everything outside that box will be garbage.
  • int "w" (-1), int "h" (-1)
w and h are the width and height of the processed box. -1 means that the box extends to the lower right corner of the video. That also means that default settings are meant to process the whole picture.
  • int "y" (3), int "u" (1), int "v" (1)
These three values describe the actual processing mode that is to be used on each plane / channel. Here is how the modes are coded:
  • x = -255..0 : all the pixels of the plane will be set to -x.
  • x = 1 : the plane will not be processed. That means the content of the plane after the filter is pure garbage.
  • x = 2 : the plane of the first input clip will be copied.
  • x = 3 : the plane will be processed with the processing the filter is designed to do.
  • x = 4 (when applicable) : the plane of the second input clip will be copied.
  • x = 5 (when applicable) : the plane of the third input clip will be copied.
As you can see, defaults parameters are chosen to only process the luma, and not to care about the chroma. It's because most video processing doesn't touch the chroma when handling 4:2:0.
  • string "chroma" ("")
When defined, the value contained in this string will overwrite the u & v processing modes. This is a nice addition proposed by mg262 that makes the filter more user friendly. Allowed values for chroma are:
  • "process" : set u = v = 3.
  • "copy" or "copy first" : set u = v = 2.
  • "copy second" : set u = v = 4.
  • "copy third" : set u = v = 5.
  • "xxx", where xxx is a number : set u = v = -xxx.

Filters

Here is an exhaustive list of the filters contained in MaskTools2 (see developer's page here for more information)

Filter Description Color format
Masks creation
Mt_edge

Creates edge masks.

YV12
Mt_motion

Creates motion masks.

YV12
Masks operation
Mt_invert

Inverses masks.

YV12
Mt_binarize

Transforms soft masks into hard masks.

YV12
Mt_logic

Combines masks using logic operators.

YV12
Mt_hysteresis

Combines masks making the first one to grow into the second.

YV12
Masks merging
Mt_merge

Merges two clips according to a mask.

YV12
Morphologic operators
Mt_expand

Expands the mask / the video.

YV12
Mt_inpand

Inpands the mask / the video.

YV12
Mt_inflate

Inflates the mask / the video.

YV12
Mt_deflate

Deflates the mask / the video.

YV12
LUT operators
Mt_lut

Applies an expression to all the pixels of a mask / video.

YV12
Mt_lutxy

Applies an expression to all the pixels of two masks / videos.

YV12
Mt_lutxyz

Applies an expression to all the pixels of three masks / videos.

YV12
Mt_lutf

Creates a uniform picture from the collection of computation on pixels of two clips.

YV12
Mt_luts

Applies an expression taking neighbouring pixels into.

YV12
Mt_lutsx

Applies an expression taking neighbouring pixels into, in a different way.

YV12
Mt_lutspa

Computes the value of a pixel according to its spatial position.

YV12
Support operators
Mt_makediff

Substracts two clips.

YV12
Mt_adddiff

Adds back a difference of two clips.

YV12
Mt_clamp

Clamps a clip between two other clips.

YV12
Mt_average

Averages two clips.

YV12
Convolutions
Mt_convolution

Applies a separable convolution on the picture.

YV12
Mt_mappedblur

Applies a special 3x3 convolution on the picture.

YV12
Helpers
Mt_square

Creates a string describing a square.

YV12
Mt_rectangle

Creates a string describing a rectangle.

YV12
Mt_freerectangle

Creates a string describing a rectangle.

YV12
Mt_diamond

Creates a string describing a diamond.

YV12
Mt_losange

Creates a string describing a lozenge.

YV12
Mt_freelosange

Creates a string describing a lozenge.

YV12
Mt_circle

Creates a string describing a circle.

YV12
Mt_ellipse

Creates a string describing an ellipse.

YV12
Mt_freeellipse

Creates a string describing an ellipse.

YV12
Mt_polish

Creates a reverse polish expression from an infix one.

YV12
Mt_infix

Creates an infix expression from a reverse polish one.

YV12

Reverse polish notation

A lot of filters accept custom functions defined by an expression written in reverse polish notation. You may not be accustomed to this notation, so here are a few pointers :

  • The basic concept behind the notation is to write the operator / function after the arguments. Hence, "x + y" in infix notation becomes in reverse polish "x y +". "(3 + 5) * x" would become "3 5 + x *".
  • As you noticed in the last example, the great asset of the notation is that it doesn't need parenthesis. The expresion that would have been enclosed in parenthesis ( "3 + 5" ) is correctly computed, because we read the expression from left to right, and because when the "+" is encountered, its two operands are unmistakenly known.
  • The supported operators are : "+", "-", "*", "/", "%" (modulo) and "^" (power)
  • The supported functions are : "sin", "cos", "tan", "asin", "acos", "atan", "exp", "log", "abs", "round", "clip", "min", "max".
  • Making the assumption that a positive float is "true", and a negative one is "false", we can also define boolean operators : "&", "|", "&!" (and not), "Β°" (xor).
  • We can create boolean values with the following comparison operators : "<", ">", "<=", ">=", "!=", "==", "=".
  • The variable "x" and "y" (when applicable) contains the value of the pixel. It's an integer that ranges from 0 to 255.
  • The constant "pi" can be used.
  • Finally, there's a ternary operator : "?", which acts like a "if .. then .. else .."
  • All the computations are made on floats, and the final result is rounded to the nearest integer, in the range [0..255].
  • Throughout the whole documentation, you'll be able to found plenty of examples.

Changelog

See the latest version of the Masktools2 changelog.

Links

MaskTools2 Homepage

The latest version can always be downloaded from manao4.free.fr or its Doom9 thread.

Personal tools