MaskTools2/Mt edge

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(overhaul)
m (Syntax and Parameters)
 
Line 22: Line 22:
 
::{{Par2|mode|string|"sobel"}}
 
::{{Par2|mode|string|"sobel"}}
 
:::{{Template:FuncDef3|mode}} chooses the 3x3 convolution kernel used for the mask computing.  
 
:::{{Template:FuncDef3|mode}} chooses the 3x3 convolution kernel used for the mask computing.  
:::There are 7 predefined kernel, "sobel", "roberts", "laplace", "hprewitt", "prewitt", "cartoon" and "min/max".
+
:::There are 7 predefined kernel, "sobel", "roberts", "laplace", "cartoon", "min/max", "hprewitt", and "prewitt".
 
:::Additionally, you can also enter also a custom 3x3 kernel. The normalization factor of the kernel is automatically
 
:::Additionally, you can also enter also a custom 3x3 kernel. The normalization factor of the kernel is automatically
 
:::computed and ceiled to the closest power of 2, to allow faster processing. You can specify your own normalization
 
:::computed and ceiled to the closest power of 2, to allow faster processing. You can specify your own normalization
Line 74: Line 74:
 
| 1
 
| 1
 
|}
 
|}
 +
 +
:::*"cartoon" behaves like "roberts", but takes only negative edges into account.
 +
 +
:::*"min/max" computes the local contrast (local max - local min).
  
 
:::*"hprewitt" is equivalent to:  
 
:::*"hprewitt" is equivalent to:  
Line 80: Line 84:
 
:::* "prewitt" is a more robust kernel and is equivalent to:
 
:::* "prewitt" is a more robust kernel and is equivalent to:
 
::::<pre>mt_logic(mt_logic(mt_edge("1 1 0 1 0 -1 0 -1 -1 1"),mt_edge("1 1 1 0 0 0 -1 -1 -1 1"),mode="max"),mt_logic(mt_edge("1 0 -1 1 0 -1 1 0 -1 1"),mt_edge("0 -1 -1 1 0 -1 1 1 0 1"),mode="max"),mode="max")</pre>
 
::::<pre>mt_logic(mt_logic(mt_edge("1 1 0 1 0 -1 0 -1 -1 1"),mt_edge("1 1 1 0 0 0 -1 -1 -1 1"),mode="max"),mt_logic(mt_edge("1 0 -1 1 0 -1 1 0 -1 1"),mt_edge("0 -1 -1 1 0 -1 1 1 0 1"),mode="max"),mode="max")</pre>
 
:::*"cartoon" behaves like "roberts", but takes only negative edges into account.
 
 
:::*"min/max" computes the local contrast (local max - local min).
 
 
<br>
 
<br>
 
::{{Par2|thY1|int|10}}
 
::{{Par2|thY1|int|10}}
Line 90: Line 90:
 
::{{Par2|thC2|int|10}}
 
::{{Par2|thC2|int|10}}
 
:::{{Template:FuncDef3|thY1}} and {{Template:FuncDef3|thY2}} are the low and high threshold for luma. {{Template:FuncDef3|thC1}} and {{Template:FuncDef3|thC2}} are the same but for chroma.  
 
:::{{Template:FuncDef3|thY1}} and {{Template:FuncDef3|thY2}} are the low and high threshold for luma. {{Template:FuncDef3|thC1}} and {{Template:FuncDef3|thC2}} are the same but for chroma.  
:::Under thX1, the pixel is set to zero, over thX2, to 255, and in between, left untouched.
+
:::If the pixel value is less than thX1, the pixel is set to 0, if it's greater than thX2 then it's set to 255, anything in between is left untouched.
 +
 
 +
:::Range: 0 to 255
 
<br>
 
<br>
 
::{{Par2|Y|int|3}}
 
::{{Par2|Y|int|3}}

Latest revision as of 18:49, 4 August 2014



Back to MaskTools2



[edit] Description

This filter creates an edge mask. The edge-finding algorithm uses a (3x3) convolution kernel, and the result of the convolution is then thresholded with thY1 and thY2 (luma) and thC1 and thC2 (chroma).
The thresholding happens like this (r is the result of the convolution):
  • r <= th1 gives 0.
  • th1 < r <= th2 gives r.
  • th2 < r gives 255.


[edit] Syntax and Parameters

mt_edge (clip, string "mode", int "thY1", int "thY2", int "thC1", int "thC2", int "Y", int "U", int "V", string "chroma", int "offX", int "offY" int "w", int "h")


clip   =
Input clip


string  mode = "sobel"
mode chooses the 3x3 convolution kernel used for the mask computing.
There are 7 predefined kernel, "sobel", "roberts", "laplace", "cartoon", "min/max", "hprewitt", and "prewitt".
Additionally, you can also enter also a custom 3x3 kernel. The normalization factor of the kernel is automatically
computed and ceiled to the closest power of 2, to allow faster processing. You can specify your own normalization
factor by adding it to the list of coefficients ( "1 1 1 1 -8 1 1 1 1 8" for example ).


  • "sobel" uses the kernel "0 -1 0 -1 0 1 0 1 0"
0 -1 0
-1 0 1
0 1 0
  • "roberts": "0 0 0 0 2 -1 0 -1 0"
0 0 0
0 2 -1
0 -1 0
  • "laplace": "1 1 1 1 -8 1 1 1 1"
1 1 1
1 -8 1
1 1 1
  • "cartoon" behaves like "roberts", but takes only negative edges into account.
  • "min/max" computes the local contrast (local max - local min).
  • "hprewitt" is equivalent to:
mt_logic(mt_edge("1 2 1 0 0 0 -1 -2 -1 1"), mt_edge("1 0 -1 2 0 -2 1 0 -1 1"), mode="max")
  • "prewitt" is a more robust kernel and is equivalent to:
mt_logic(mt_logic(mt_edge("1 1 0 1 0 -1 0 -1 -1 1"),mt_edge("1 1 1 0 0 0 -1 -1 -1 1"),mode="max"),mt_logic(mt_edge("1 0 -1 1 0 -1 1 0 -1 1"),mt_edge("0 -1 -1 1 0 -1 1 1 0 1"),mode="max"),mode="max")


int  thY1 = 10
int  thY2 = 10
int  thC1 = 10
int  thC2 = 10
thY1 and thY2 are the low and high threshold for luma. thC1 and thC2 are the same but for chroma.
If the pixel value is less than thX1, the pixel is set to 0, if it's greater than thX2 then it's set to 255, anything in between is left untouched.
Range: 0 to 255


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.


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.
  • "xxx", where xxx is a number : set u = v = -xxx.


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.
This also means that default settings are meant to process the whole picture.




Back to MaskTools2


Personal tools