Log in

View Full Version : MaskTools2 for VapourSynth


MysteryX
26th June 2021, 18:51
Creating this thread for reference if others are looking to use MaskTools2 in VapourSynth.

The library itself has not been ported, but most functions can easily be replaced.

mt_lutspa: VapourSynth-Draw (https://github.com/kewenyu/VapourSynth-Draw)

mt_motion: MotionMask (https://github.com/dubhater/vapoursynth-motionmask)

mt_lut and mt_lutxy: Expr (http://www.vapoursynth.com/doc/functions/expr.html)
Note: Expr does not support Pixel Addressing (http://avisynth.nl/index.php/Expr#Pixel_addressing) (neither does mt_lut) but they may add it in the future (https://github.com/vapoursynth/vapoursynth/issues/703)

mt_binarize: Binarize (http://www.vapoursynth.com/doc/functions/binarize.html)

mt_merge: MaskedMerge (http://www.vapoursynth.com/doc/functions/maskedmerge.html#std.MaskedMerge)

mt_inpand and mt_expand: Minimum/Maximum (http://www.vapoursynth.com/doc/functions/minimum_maximum.html)

Maximum() however gives square output

mt_expand(mode= mt_circle(zero=true, radius=1))
# can be replaced with
std.Maximum(coordinates=[0, 1, 0, 1, 1, 0, 1, 0])

mt_expand(mode= mt_circle(zero=true, radius=8)
# best replacement I found, let me now if you find better
C = C.std.Maximum()
C = C.std.Maximum(coordinates=[0, 1, 0, 1, 1, 0, 1, 0])
C = C.std.Maximum()
C = C.std.Maximum(coordinates=[0, 1, 0, 1, 1, 0, 1, 0])
C = C.std.Maximum()
C = C.std.Maximum(coordinates=[0, 1, 0, 1, 1, 0, 1, 0])


Other useful functions to work with masks

Overlay (https://github.com/HomeOfVapourSynthEvolution/havsfunc/blob/019ad633afa2982dfee8959435b2a0deb862c9f7/havsfunc.py#L5427)

Blur: Convolution (http://www.vapoursynth.com/doc/functions/convolution.html)

Blur(1.0) can be replaced with std.Convolution(matrix=[1, 2, 1, 2, 4, 2, 1, 2, 1]) or std.Convolution(matrix=[10, 20, 10, 20, 40, 20, 10, 20, 10]) gives the exact same result. You can fine-tune the weighting to your needs. This gives similar to Blur(0.6): std.Convolution(matrix=[0, 1, 0, 1, 3, 1, 0, 1, 0]).

You can add any further info on the topic to this thread.

_Al_
26th June 2021, 20:11
you can do RELATIVE pixel addressing using python code, like in this example, where you create shifted clips and then using std.Expr() for calculations:
https://forum.doom9.org/showthread.php?t=181803
using image shifting using vapoursynth std.resize.XXX(src_left=..., src_top=...). This function uses mirror pixel if particular pixel on the edge is not available, so this might not be aplicable also.

But I understand you guys want libraries to implement them in your new libraries, not python code, just pointing this out.

kedautinh12
27th June 2021, 01:07
mt_deflate/mt_inflate
http://www.vapoursynth.com/doc/functions/deflate_inflate.html

mt_makediff
http://www.vapoursynth.com/doc/functions/makediff.html

mt_invert
http://www.vapoursynth.com/doc/functions/invert.html

mt_square, mt_circle, mt_diamond, mt_rectangle, mt_ellipse, mt_losange, mt_freerectangle, mt_freeellipse, mt_freelosange in parameter mode of mt_inpand and mt_expand same parameter coordinates of Minium/Maxium
http://www.vapoursynth.com/doc/functions/minimum_maximum.html

mt_convolution
http://www.vapoursynth.com/doc/functions/convolution.html

MysteryX
27th June 2021, 04:26
Actually most functions are part of VapourSynth core.


mt_square, mt_circle, mt_diamond, mt_rectangle, mt_ellipse, mt_losange, mt_freerectangle, mt_freeellipse, mt_freelosange in parameter mode of mt_inpand and mt_expand same parameter coordinates of Minium/Maxium
http://www.vapoursynth.com/doc/functions/minimum_maximum.html

Min/Max functions unfortunately don't offer that much flexibility. That's the only thing I haven't been able to properly port so far.

kedautinh12
30th June 2021, 07:25
mt_average
http://www.vapoursynth.com/doc/functions/merge.html

mt_adddiff
http://www.vapoursynth.com/doc/functions/mergediff.html

MysteryX
1st July 2021, 20:12
Expressions with pixel addressing are now supported (https://github.com/AkarinVS/vapoursynth-plugin/releases/tag/v0.60)

zorr
4th July 2021, 18:11
mt_hysteresis
misc.Hysteresis (http://www.vapoursynth.com/doc/plugins/misc.html)