Layer
Raffriff42 (Talk | contribs) (note AVS+ differences) |
Raffriff42 (Talk | contribs) m (corrections etc) |
||
Line 14: | Line 14: | ||
:: The underlying clip, which determines the size and all other video and audio properties of the result. | :: The underlying clip, which determines the size and all other video and audio properties of the result. | ||
::Color format must be [[YUY2]] or [[RGB32]]. | ::Color format must be [[YUY2]] or [[RGB32]]. | ||
− | ::{{AvsPluscon}} also supports [[RGB64 | + | ::{{AvsPluscon}} also supports [[RGB64]]. |
:{{Par2|overlay_clip|clip|}} | :{{Par2|overlay_clip|clip|}} | ||
Line 34: | Line 34: | ||
[[File:Layer-example-add.png]] | [[File:Layer-example-add.png]] | ||
|style="vertical-align:top"| This is the default mode. Equivalent to [[Overlay]](mode="blend").<br>{{FuncArg|overlay_clip}} will be copied on top of the original, in proportion to {{FuncArg|level}}, and subject to the alpha channel. <br><br>The difference between {{FuncArg|base_clip}} and {{FuncArg|overlay_clip}} is multiplied with alpha and added to {{FuncArg|base_clip}}. | |style="vertical-align:top"| This is the default mode. Equivalent to [[Overlay]](mode="blend").<br>{{FuncArg|overlay_clip}} will be copied on top of the original, in proportion to {{FuncArg|level}}, and subject to the alpha channel. <br><br>The difference between {{FuncArg|base_clip}} and {{FuncArg|overlay_clip}} is multiplied with alpha and added to {{FuncArg|base_clip}}. | ||
− | *alpha=0 → only {{FuncArg|base_clip}} visible | + | *alpha=0{{D}} → only {{FuncArg|base_clip}} visible |
− | *alpha=128 → {{FuncArg|base_clip}} and {{FuncArg|overlay_clip}} equally blended | + | *alpha=128{{D}} → {{FuncArg|base_clip}} and {{FuncArg|overlay_clip}} equally blended |
− | *alpha=255 → only {{FuncArg|overlay_clip}} visible | + | *alpha=255{{D}} → only {{FuncArg|overlay_clip}} visible |
Formula used : | Formula used : | ||
*RGB: [[File:Layer-Eq1.png]] | *RGB: [[File:Layer-Eq1.png]] | ||
Line 58: | Line 58: | ||
|style="vertical-align:top"| [[File:Layer-example-mul-rgb.png]] | |style="vertical-align:top"| [[File:Layer-example-mul-rgb.png]] | ||
|style="vertical-align:top"| {{FuncArg|base_clip}} multiplied by {{FuncArg|overlay_clip}}. This will generally make the output darker. | |style="vertical-align:top"| {{FuncArg|base_clip}} multiplied by {{FuncArg|overlay_clip}}. This will generally make the output darker. | ||
− | *alpha=0 → only {{FuncArg|base_clip}} visible. | + | *alpha=0{{D}} → only {{FuncArg|base_clip}} visible. |
− | *alpha=255 → approx. the same luminance as {{FuncArg|base_clip}} but with the colors of {{FuncArg|overlay_clip}}. | + | *alpha=255{{D}} → approx. the same luminance as {{FuncArg|base_clip}} but with the colors of {{FuncArg|overlay_clip}}. |
See [http://docs.gimp.org/2.8/en/gimp-concepts-layer-modes.html#layer-mode-multiply GIMP: Multiply] | See [http://docs.gimp.org/2.8/en/gimp-concepts-layer-modes.html#layer-mode-multiply GIMP: Multiply] | ||
|- | |- | ||
Line 72: | Line 72: | ||
::* 0 – no effect: {{FuncArg|base_clip}} is returned unchanged | ::* 0 – no effect: {{FuncArg|base_clip}} is returned unchanged | ||
::* 257 (256 for YUY2) – maximum strength | ::* 257 (256 for YUY2) – maximum strength | ||
+ | ::{{AvsPluscon}} [[Autoscale_parameter|autoscaled]] – works without changes at all bit depths. | ||
:{{Par2|x|int|0}} | :{{Par2|x|int|0}} | ||
Line 90: | Line 91: | ||
There are some differences in the behaviour and the allowed parameter depending on the color format and the operation; here are the details: | There are some differences in the behaviour and the allowed parameter depending on the color format and the operation; here are the details: | ||
− | *There is no mask (alpha channel) in [[YUY2]], so the alpha channel is assumed to be fully opaque (255) everywhere. | + | *There is no mask (alpha channel) in [[YUY2]], so the alpha channel is assumed to be fully opaque (255{{D}}) everywhere. |
*In [[RGB32]] the {{FuncArg|overlay_clip}} alpha channel is multiplied with {{FuncArg|level}}, so the resulting alpha is | *In [[RGB32]] the {{FuncArg|overlay_clip}} alpha channel is multiplied with {{FuncArg|level}}, so the resulting alpha is | ||
:: (alpha * {{FuncArg|level}} + 1) / 256. | :: (alpha * {{FuncArg|level}} + 1) / 256. | ||
− | :This means for full strength of operation, alpha has to be 255 and {{FuncArg|level}} has to be 257. | + | :This means for full strength of operation, alpha has to be 255{{D}} and {{FuncArg|level}} has to be 257. |
Line 119: | Line 120: | ||
:{{Par2|mask_clip|clip|}} | :{{Par2|mask_clip|clip|}} | ||
− | :: Alpha-mask source, as described above. Size must match {{FuncArg|clip}} | + | :: Alpha-mask source, as described above. Size and color format must match {{FuncArg|clip}}. |
− | + | ||
====Examples==== | ====Examples==== | ||
Line 141: | Line 141: | ||
:{{Par2|clip|clip|}} | :{{Par2|clip|clip|}} | ||
:: Source clip. Alpha channel will be set to opaque. Color format must be [[RGB32]]. | :: Source clip. Alpha channel will be set to opaque. Color format must be [[RGB32]]. | ||
− | ::{{AvsPluscon}} also supports [[RGB64]] | + | ::{{AvsPluscon}} also supports [[RGB64]], [[PlanarRGBA]] and [[YUVA]]. |
</div> | </div> | ||
Line 149: | Line 149: | ||
Clears pixels in the alpha channel by comparing to a transparent {{FuncArg|color}} (default black). | Clears pixels in the alpha channel by comparing to a transparent {{FuncArg|color}} (default black). | ||
− | Each pixel with a color differing less than ({{FuncArg|tolB}},{{FuncArg|tolR}},{{FuncArg|tolG}}) (default 10) is set to transparent (black); otherwise it is left unchanged – note, it is NOT set to opaque (white). That's why you might need '''ResetMask''' before applying this filter. This behaviour allows an aggregate mask to be constructed with multiple calls to '''ColorKeyMask'''. | + | Each pixel with a color differing less than ({{FuncArg|tolB}},{{FuncArg|tolR}},{{FuncArg|tolG}}) (default 10{{D}}) is set to transparent (black); otherwise it is left unchanged – note, it is NOT set to opaque (white). That's why you might need '''ResetMask''' before applying this filter. This behaviour allows an aggregate mask to be constructed with multiple calls to '''ColorKeyMask'''. |
When {{FuncArg|tolR}} or {{FuncArg|tolG}} are not set, they get the value of {{FuncArg|tolB}} by default. Normally you start with a '''ResetMask''', then chain a few calls to '''ColorKeyMask''' to cause transparent holes where each color of interest occurs. See [[Overlay]] for examples. | When {{FuncArg|tolR}} or {{FuncArg|tolG}} are not set, they get the value of {{FuncArg|tolB}} by default. Normally you start with a '''ResetMask''', then chain a few calls to '''ColorKeyMask''' to cause transparent holes where each color of interest occurs. See [[Overlay]] for examples. | ||
Line 162: | Line 162: | ||
::Transparent color. Default black. | ::Transparent color. Default black. | ||
− | :{{Par2|tolB|int|10}} | + | :{{Par2|tolB|int|10{{Template:D}}}} |
:{{Par2|tolG|int|(tolB)}} | :{{Par2|tolG|int|(tolB)}} | ||
:{{Par2|tolR|int|(tolB)}} | :{{Par2|tolR|int|(tolB)}} |
Revision as of 12:27, 28 April 2017
Contents |
Layer
Layer (aka overlay, blend, merge) two clips of possibly different sizes, but with the same color format.
For pixel-wise transparency information, the alpha channel of an RGBA overlay_clip is used as a mask.
Layer( clip base_clip, clip overlay_clip [, string op, int level, int x, int y, int threshold, bool use_chroma ] )
- clip base_clip =
- clip overlay_clip =
- The clip which is merged onto clip. If RGB32, the alpha channel is used as a mask.
- Color format must match base_clip.
- string op = "add"
- The merge operation to be performed, which can be one of the following:
Op | Example | Description |
---|---|---|
add | This is the default mode. Equivalent to Overlay(mode="blend"). overlay_clip will be copied on top of the original, in proportion to level, and subject to the alpha channel. The difference between base_clip and overlay_clip is multiplied with alpha and added to base_clip.
Formula used : | |
subtract | base_clip minus overlay_clip. The same as add, but overlay_clip is inverted before adding. If both clips are equal and level=128, a flat gray field is returned; compare to Subtract. | |
lighten | Copy overlay_clip over base_clip in areas where overlay_clip is lighter by threshold. Performs the same operation as add, but only when overlay_clip is BRIGHTER than base_clip. use_chroma must be true.
| |
darken | Copy overlay_clip over base_clip in areas where overlay_clip is darker by threshold. The same as "lighten", but it is performed only when overlay_clip is DARKER than base_clip. use_chroma must be true.
| |
mul | base_clip multiplied by overlay_clip. This will generally make the output darker.
See GIMP: Multiply | |
fast | Like add, but without masking. use_chroma must be true; level and threshold are not used. The result is simply the average of base_clip and overlay_clip. |
- int level = (maximum)
- The strength of the performed operation:
- 0 – no effect: base_clip is returned unchanged
- 257 (256 for YUY2) – maximum strength
- AVS+ autoscaled – works without changes at all bit depths.
- The strength of the performed operation:
- int x = 0
- int y = 0
- offset position of overlay_clip
- int threshold = 0
- Changes the transition point of op = "darken", "lighten."
- bool use_chroma = true
- Use chroma of the overlay_clip. Default=true. When false, only luma is used.
- Must be true for op = "darken", "lighten", "add."
Audio, FrameRate and FrameCount are taken from the first clip.
There are some differences in the behaviour and the allowed parameter depending on the color format and the operation; here are the details:
- There is no mask (alpha channel) in YUY2, so the alpha channel is assumed to be fully opaque (255d) everywhere.
- In RGB32 the overlay_clip alpha channel is multiplied with level, so the resulting alpha is
- (alpha * level + 1) / 256.
- This means for full strength of operation, alpha has to be 255d and level has to be 257.
Examples
- Layer can be used to combine two captures of different broadcasts for reducing noise. A discussion of this idea can be found here. Of course you have to ensure that the frames of the two clips match exactly -- use Trim or DeleteFrame as necessary. A sample script:
clip1 = AviSource("capture-pass-1.avi").ConvertToYUY2 clip2 = AviSource("capture-pass-2.avi").ConvertToYUY2.Trim(101, 0) return Layer(clip1, clip2, "fast")
Mask
Applies a defined alpha-mask to a clip, by converting RGB32-only mask_clip to greyscale and copying that greyscale information to the alpha channel of RGB32-only clip. In the alpha channel, "black" means transparent and "white" means opaque. For those of you who familiar with Photoshop masks, the concept is the same. In fact you can create a black and white photo in Photoshop, load it in your script and use it as a mask.
Mask(clip clip, clip mask_clip)
- clip clip =
- The base clip, which determines the size and all other video and audio properties of the result.
- Color format must be RGB32.
- AVS+ also supports RGB64 and PlanarRGBA.
- clip mask_clip =
- Alpha-mask source, as described above. Size and color format must match clip.
Examples
Suppose "ss.jpg" is a snapshot from a video clip, which served as a guideline to create the mask using Paint. We use ImageSource to load the image in the script and Mask to apply it.
bg = AviSource("01gray.avi").ConvertToRGB32 # here is the background clip mk = ImageSource("ss.jpg").ConvertToRGB32 # load the image top = AviSource("k3.avi").ConvertToRGB32.Mask(mk) # load the top layer clip and apply the mask to it Layer(bg, top) # layer the background and the top layer with mask
ResetMask
Applies an opaque (white) alpha channel to a clip. The alpha channel of an RGB32 clip is not always well-defined, depending on the source (it may contain random data); this filter is a fast way to apply an all-white mask.
ResetMask(clip clip)
- clip clip =
- Source clip. Alpha channel will be set to opaque. Color format must be RGB32.
- AVS+ also supports RGB64, PlanarRGBA and YUVA.
ColorKeyMask
Clears pixels in the alpha channel by comparing to a transparent color (default black).
Each pixel with a color differing less than (tolB,tolR,tolG) (default 10d) is set to transparent (black); otherwise it is left unchanged – note, it is NOT set to opaque (white). That's why you might need ResetMask before applying this filter. This behaviour allows an aggregate mask to be constructed with multiple calls to ColorKeyMask.
When tolR or tolG are not set, they get the value of tolB by default. Normally you start with a ResetMask, then chain a few calls to ColorKeyMask to cause transparent holes where each color of interest occurs. See Overlay for examples.
ColorKeyMask(clip clip, int color [, int tolB, int tolG, int tolR])
- clip clip =
- Source clip. Color format must be RGB32.
- AVS+ also supports RGB64 and PlanarRGBA.
- int color = black
- Transparent color. Default black.
- int tolB = 10d
- int tolG = (tolB)
- int tolR = (tolB)
- Color tolerance. See description above.
Changelog
v2.58 | ColorKeyMask: Added separate tolerance levels. |