From 2a532a7376db79ba48ba9f1b4dea1d9668c5cd60 Mon Sep 17 00:00:00 2001 From: Ichunjo Date: Tue, 12 Nov 2024 05:31:16 +0100 Subject: [PATCH 1/2] Replace `maximum` by `expand` & add expand_mode param --- vsmasktools/hardsub.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/vsmasktools/hardsub.py b/vsmasktools/hardsub.py index 1904345..0ce13d6 100644 --- a/vsmasktools/hardsub.py +++ b/vsmasktools/hardsub.py @@ -17,9 +17,9 @@ ) from .abstract import DeferredMask, GeneralMask -from .edge import Sobel +from .edge import SobelStd from .morpho import Morpho -from .types import GenericMaskT +from .types import GenericMaskT, XxpandMode from .utils import max_planes, normalize_mask __all__ = [ @@ -164,13 +164,17 @@ class HardsubSignFades(HardsubMask): highpass: float expand: int edgemask: GenericMaskT + expand_mode: XxpandMode def __init__( - self, *args: Any, highpass: float = 0.0763, expand: int = 8, edgemask: GenericMaskT = Sobel, **kwargs: Any + self, *args: Any, highpass: float = 0.0763, expand: int = 8, edgemask: GenericMaskT = SobelStd, + expand_mode: XxpandMode = XxpandMode.RECTANGLE, + **kwargs: Any ) -> None: self.highpass = highpass self.expand = expand self.edgemask = edgemask + self.expand_mode = expand_mode super().__init__(*args, **kwargs) @@ -186,41 +190,47 @@ def _mask(self, clip: vs.VideoNode, ref: vs.VideoNode, **kwargs: Any) -> vs.Vide [clipedge, refedge], f'x y - {highpass} < 0 {ExprToken.RangeMax} ?' ).std.Median() - return Morpho.inflate(Morpho.maximum(mask, iterations=self.expand), iterations=4) + return Morpho.inflate(Morpho.expand(mask, self.expand, mode=self.expand_mode), iterations=4) class HardsubSign(HardsubMask): """ Hardsub scenefiltering helper using `Zastin `_'s hardsub mask. - :param thr: Binarization threshold, [0, 1] (Default: 0.06). - :param expand: std.Maximum iterations (Default: 8). - :param inflate: std.Inflate iterations (Default: 7). + :param thr: Binarization threshold, [0, 1] (Default: 0.06). + :param minimum: std.Minimum iterations (Default: 1). + :param expand: std.Maximum iterations (Default: 8). + :param inflate: std.Inflate iterations (Default: 7). + :param expand_mode: Specifies the XxpandMode used for mask growth (Default: XxpandMode.RECTANGLE). """ thr: float minimum: int expand: int inflate: int + expand_mode: XxpandMode def __init__( - self, *args: Any, thr: float = 0.06, minimum: int = 1, expand: int = 8, inflate: int = 7, **kwargs: Any + self, *args: Any, thr: float = 0.06, minimum: int = 1, expand: int = 8, inflate: int = 7, + expand_mode: XxpandMode = XxpandMode.RECTANGLE, + **kwargs: Any ) -> None: self.thr = thr self.minimum = minimum self.expand = expand self.inflate = inflate + self.expand_mode = expand_mode super().__init__(*args, **kwargs) def _mask(self, clip: vs.VideoNode, ref: vs.VideoNode, **kwargs: Any) -> vs.VideoNode: hsmf = norm_expr([clip, ref], 'x y - abs') - hsmf = hsmf.resize.Point(format=clip.format.replace(subsampling_w=0, subsampling_h=0).id) # type: ignore + hsmf = Point.resample(hsmf, clip.format.replace(subsampling_w=0, subsampling_h=0)) # type: ignore hsmf = ExprOp.MAX(hsmf, split_planes=True) hsmf = Morpho.binarize(hsmf, self.thr) hsmf = Morpho.minimum(hsmf, iterations=self.minimum) - hsmf = Morpho.maximum(hsmf, iterations=self.expand) + hsmf = Morpho.expand(hsmf, self.expand, mode=self.expand_mode) hsmf = Morpho.inflate(hsmf, iterations=self.inflate) return hsmf.std.Limiter() From 541072cf50905c083ef18816bbbbdff29cd9b610 Mon Sep 17 00:00:00 2001 From: Ichunjo Date: Sat, 16 Nov 2024 04:37:06 +0100 Subject: [PATCH 2/2] Switch to Bilinear --- vsmasktools/hardsub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vsmasktools/hardsub.py b/vsmasktools/hardsub.py index 0ce13d6..1e1a522 100644 --- a/vsmasktools/hardsub.py +++ b/vsmasktools/hardsub.py @@ -6,7 +6,7 @@ from typing import Any, Type from vsexprtools import ExprOp, ExprToken, expr_func, norm_expr -from vskernels import Catrom, Point +from vskernels import Bilinear, Catrom, Point from vsrgtools.util import mean_matrix from vssource import IMWRI, Indexer from vstools import ( @@ -224,7 +224,7 @@ def __init__( def _mask(self, clip: vs.VideoNode, ref: vs.VideoNode, **kwargs: Any) -> vs.VideoNode: hsmf = norm_expr([clip, ref], 'x y - abs') - hsmf = Point.resample(hsmf, clip.format.replace(subsampling_w=0, subsampling_h=0)) # type: ignore + hsmf = Bilinear.resample(hsmf, clip.format.replace(subsampling_w=0, subsampling_h=0)) # type: ignore hsmf = ExprOp.MAX(hsmf, split_planes=True)