def ringing_mask(
clip: vs.VideoNode,
rad: int = 2, brz: float = 0.35,
thmi: float = 0.315, thma: float = 0.5,
thlimi: float = 0.195, thlima: float = 0.392,
credit_mask: GenericMaskT = Prewitt, **kwargs: Any
) -> vs.VideoNode:
assert check_variable(clip, ringing_mask)
thmi, thma, thlimi, thlima = (
scale_mask(t, 32, clip) for t in [thmi, thma, thlimi, thlima]
)
blur_kernel = BlurMatrix.BINOMIAL(1, mode=ConvMode.SQUARE)
edgemask = normalize_mask(credit_mask, plane(clip, 0), **kwargs)
edgemask = limiter(edgemask)
light = norm_expr(edgemask, f'x {thlimi} - {thma - thmi} / {ExprToken.RangeMax} *')
shrink = Morpho.dilation(light, rad)
shrink = Morpho.binarize(shrink, brz)
shrink = Morpho.erosion(shrink, 2)
shrink = blur_kernel(shrink, passes=2)
strong = norm_expr(edgemask, f'x {thmi} - {thlima - thlimi} / {ExprToken.RangeMax} *')
expand = Morpho.dilation(strong, iterations=rad)
mask = norm_expr([expand, strong, shrink], 'x y z max -')
return ExprOp.convolution('x', blur_kernel, premultiply=2, multiply=2, clamp=True)(mask)