MaskTools2/Mt merge

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Syntax and Parameters: New parameters 2.2.15-)
(Description: Formula for 10+ bit depths)
Line 2: Line 2:
 
== Description ==
 
== Description ==
 
It's the backbone of the framework. It merges two clips according to the mask. The bigger the mask value, the more the second clip will be taken into account.<br/>
 
It's the backbone of the framework. It merges two clips according to the mask. The bigger the mask value, the more the second clip will be taken into account.<br/>
For 8 bits the actual formula is:<br>
 
y = ((256 - m) * x1 + m * x2 + 128) / 256
 
  
Since v2.2.7: keep original pixels from clip1/2 when mask is exactly 0 or 255:<br>
+
<br>For 8 bits the actual formula is:
y = (m == 0) ? x1 : (m == 255) ? x2 : ((256 - m) * x1 + m * x2 + 128) / 256
+
<br>y = ((256 - m) * x1 + m * x2 + 128) / 256
<br>
+
 
 +
<br>Since v2.2.7: keep original pixels from clip1/2 when mask is exactly 0 or 255:
 +
<br>y = (m == 0) ? x1 : (m == 255) ? x2 : ((256 - m) * x1 + m * x2 + 128) / 256
 +
 
 +
<br>For 10-12-14-16 bits the minimum value is 0, maximum value is 1023, 4095, 16383, 65535 accordingly.
 +
<br>y = (m == ''minvalue'') ? x1 : (m == ''maxvalue'') ? x2 : ((2^''bitdepth'' - m) * x1 + m * x2 + 2^(''bitdepth''-1)) / (2^''bitdepth'')
 +
 
 +
<br>For 32 bit float the actual formula is:
 +
<br>y = (1.0 - m) * x1 + m * x2
 +
 
 
<br>
 
<br>
  

Revision as of 14:11, 10 July 2018

Description

It's the backbone of the framework. It merges two clips according to the mask. The bigger the mask value, the more the second clip will be taken into account.


For 8 bits the actual formula is:
y = ((256 - m) * x1 + m * x2 + 128) / 256


Since v2.2.7: keep original pixels from clip1/2 when mask is exactly 0 or 255:
y = (m == 0) ? x1 : (m == 255) ? x2 : ((256 - m) * x1 + m * x2 + 128) / 256


For 10-12-14-16 bits the minimum value is 0, maximum value is 1023, 4095, 16383, 65535 accordingly.
y = (m == minvalue) ? x1 : (m == maxvalue) ? x2 : ((2^bitdepth - m) * x1 + m * x2 + 2^(bitdepth-1)) / (2^bitdepth)


For 32 bit float the actual formula is:
y = (1.0 - m) * x1 + m * x2


Syntax and Parameters

mt_merge (clip, clip, clip, bool "luma", int "Y", int "U", int "V", string "chroma", int "offX", int "offY", int "w", int "h")


or since v2.2.15

mt_merge (clip, clip, clip, bool "luma", float "Y", float "U", float "V", string "chroma", int "offX", int "offY", int "w", int "h", float "A", string "cplace")


clip   =
Input clip one.


clip   =
Input clip two.


clip   =
Mask input clip.


bool  luma = false
luma is a special mode, where only the luma plane of the mask is used to process all three channels.


int  Y = 3
int  U = 2
int  V = 2
int  A = 2
These 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. (-255..0 range can of course differ when non-8 bit video formats are used)
  • 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 : the plane of the second input clip will be copied.
U, V and A are defaulted to 2 (that way, the resulting clip contains the chroma (alpha) of clip1, and looks right).


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


string  cplace = "mpeg2"
  • "mpeg1" : Simple block averaging (e.g. average 2x2 pixels to a single YV12 chroma mask)
  • "mpeg2" : default
Since v2.2.15.
Parameter defines chroma placement hint for 4:2:0 and 4:2:2 formats.


Examples

mt_merge with default settings: (TO DO)

clip1 = original
clip2 = processed
mask  = mask
mt_merge(clip1, clip2, mask, Y=3, U=2, V=2, chroma="", w=-1, h=-1)




Back to MaskTools2


Personal tools