It made me think about two helper functions I wrote for this kind of task, and I thought that I could share them:
Code:
#=============================================================================
# mt_expand_multi
# mt_inpand_multi
#
# Calls mt_expand or mt_inpand multiple times in order to grow or shrink
# the mask from the desired width and height.
#
# Parameters:
# - sw : Growing/shrinking shape width. 0 is allowed. Default: 1
# - sh : Growing/shrinking shape height. 0 is allowed. Default: 1
# - mode : "rectangle" (default), "ellipse" or "losange". Replaces the
# mt_xxpand mode. Ellipses are actually combinations of
# rectangles and losanges and look more like octogons.
# Losanges are truncated (not scaled) when sw and sh are not
# equal.
# Other parameters are the same as mt_xxpand.
#=============================================================================
Function mt_expand_multi (clip src, int "thY", int "thC", string "mode",
\ int "offx", int "offy", int "w", int "h", int "y", int "u", int "v",
\ string "chroma", int "sw", int "sh")
{
sw = Default (sw, 1)
sh = Default (sh, 1)
mode = Default (mode, "rectangle")
mode_m =
\ (sw > 0 && sh > 0) ? (
\ (mode == "losange" || (mode == "ellipse" && (sw % 3) != 1))
\ ? "both" : "square"
\ )
\ : (sw > 0 ) ? "horizontal"
\ : ( sh > 0) ? "vertical"
\ : ""
(mode_m != "") ? src.mt_expand (
\ thY=thY, thC=thC, mode=mode_m,
\ offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma
\ ).mt_expand_multi (
\ thY=thY, thC=thC, mode=mode,
\ offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma,
\ sw=sw-1, sh=sh-1
\ ) : src
}
Function mt_inpand_multi (clip src, int "thY", int "thC", string "mode",
\ int "offx", int "offy", int "w", int "h", int "y", int "u", int "v",
\ string "chroma", int "sw", int "sh")
{
sw = Default (sw, 1)
sh = Default (sh, 1)
mode = Default (mode, "rectangle")
mode_m =
\ (sw > 0 && sh > 0) ? (
\ (mode == "losange" || (mode == "ellipse" && (sw % 3) != 1))
\ ? "both" : "square"
\ )
\ : (sw > 0 ) ? "horizontal"
\ : ( sh > 0) ? "vertical"
\ : ""
(mode_m != "") ? src.mt_inpand (
\ thY=thY, thC=thC, mode=mode_m,
\ offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma
\ ).mt_inpand_multi (
\ thY=thY, thC=thC, mode=mode,
\ offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma,
\ sw=sw-1, sh=sh-1
\ ) : src
}
Though I don't know if the "common" parameters are in the right order (I'm too lazy to check the mt source code).