lvsfunc.mask
Masks are used to limit where filtering takes place, and how strong the filtering applied is. lvsfunc offers a couple of masks, and they’re often used internally in other functions.
All masks also come limited by default, so you don’t need to worry about illegal ranges messing with your masked output.
|
A positional bounding box. |
|
Deferred masking interface. |
|
A wrapper for creating a detail mask to be used during denoising and/or debanding. |
|
A detail mask aimed at preserving as much detail as possible within darker areas, even if it winds up being mostly noise. |
|
A halo mask to catch basic haloing, inspired by the mask from FineDehalo. |
|
Mask expanding/inpanding function written by Zastin. |
|
Min/max mask with separate luma/chroma radii. |
- class lvsfunc.mask.BoundingBox(pos, size)
Bases:
object
A positional bounding box. Basically kagefunc.squaremask but can be configured then deferred.
Uses Position + Size, like provided by GIMP’s rectangle selection tool.
- Parameters
pos (
Union
[Position
,Tuple
[int
,int
]]) – Offset of top-left corner of the bounding box from the top-left corner of the frame. Supports either alvsfunc.types.Position
or a tuple that will be converted.size (
Union
[Size
,Tuple
[int
,int
]]) – Offset of the bottom-right corner of the bounding box from the top-left corner of the bounding box. Supports either alvsfunc.types.Size
or a tuple that will be converted.
- size: lvsfunc.types.Size
- get_mask(ref)
Get a mask representing the bounding box
- Parameters
ref (
VideoNode
) – Reference clip for format, resolution, and length.- Return type
VideoNode
- Returns
Square mask representing the bounding box.
- class lvsfunc.mask.DeferredMask(ranges=None, bound=None, *, blur=False, refframes=None)
Bases:
abc.ABC
Deferred masking interface.
Provides an interface to use different preconfigured masking functions. Provides support for ranges, reference frames, and bounding.
- Parameters
range – A single range or list of ranges to replace, compatible with
lvsfunc.misc.replace_ranges
bound (
Union
[BoundingBox
,Tuple
[Tuple
[int
,int
],Tuple
[int
,int
]],None
]) – Alvsfunc.mask.BoundingBox
or a tuple that will be converted. (Default:None
, no bounding)blur (
bool
) – Blur the bounding mask (Default: False)refframe – A single frame number to use to generate the mask or a list of frame numbers with the same length as
range
- ranges: List[Union[int, None, Tuple[Optional[int], Optional[int]]]]
- blur: bool
- bound: lvsfunc.mask.BoundingBox | None
- refframes: List[int | None]
- get_mask(clip, ref)
Get the bounded mask.
- Parameters
clip (
VideoNode
) – Sourceref (
VideoNode
) – Reference clip
- Return type
VideoNode
- Returns
Bounded mask
- lvsfunc.mask.detail_mask(clip, sigma=None, rad=3, brz_a=0.025, brz_b=0.045)
A wrapper for creating a detail mask to be used during denoising and/or debanding. The detail mask is created using debandshit’s range mask, and is then merged with Prewitt to catch lines it may have missed.
Dependencies:
VapourSynth-Bilateral (optional: sigma)
RGSF (optional: 32 bit clip)
- Parameters
clip (
VideoNode
) – Input clipsigma (
Optional
[float
]) – Sigma for Bilateral for pre-blurring (Default: False)rad (
int
) – The luma equivalent of gradfun3’s “mask” parameterbrz_a (
float
) – Binarizing thresh for the detail mask. Scaled to clip’s depth if between 0 and 1 (inclusive), else assumed to be in native range. (Default: 0.025)brz_b (
float
) – Binarizing thresh for the edge mask. Scaled to clip’s depth if between 0 and 1 (inclusive), else assumed to be in native range. (Default: 0.045)
- Return type
VideoNode
- Returns
Detail mask
- lvsfunc.mask.detail_mask_neo(clip, sigma=1.0, detail_brz=0.05, lines_brz=0.08, blur_func=None, edgemask_func=vapoursynth.core.std.Prewitt, rg_mode=17)
A detail mask aimed at preserving as much detail as possible within darker areas, even if it winds up being mostly noise.
- Parameters
clip (
VideoNode
) – Input clipsigma (
float
) – Sigma for the detail mask. Higher means more detail and noise will be caught.detail_brz (
float
) – Binarizing for the detail mask. Default values assume a 16bit clip, so you may need to adjust it yourself. Will not binarize if set to 0.lines_brz (
float
) – Binarizing for the prewitt mask. Default values assume a 16bit clip, so you may need to adjust it yourself. Will not binarize if set to 0.blur_func (
Optional
[Callable
[[VideoNode
,VideoNode
,float
],VideoNode
]]) – Blurring function used for the detail detection. Must accept the following parameters:clip
,ref_clip
,sigma
. Uses bilateral.Bilateral by default.edgemask_func (
Callable
[[VideoNode
],VideoNode
]) – Edgemasking function used for the edge detectionrg_mode (
int
) – Removegrain mode performed on the final output
- Return type
VideoNode
- Returns
Detail mask
- lvsfunc.mask.halo_mask(clip, rad=2, brz=0.35, thmi=0.315, thma=0.5, thlimi=0.195, thlima=0.392, edgemask=None)
A halo mask to catch basic haloing, inspired by the mask from FineDehalo. Most was copied from there, but some key adjustments were made to center it specifically around masking.
rx and ry are now combined into rad and expects an integer. Float made sense for FineDehalo since it uses DeHalo_alpha for dehaloing, but the masks themselves use rounded rx/ry values, so there’s no reason to bother with floats here.
All thresholds are float and will be scaled to
clip
's format. If thresholds are greater than 1, they will be asummed to be in 8-bit and scaled accordingly.- Parameters
clip (vs.VideoNode) – Input clip
rad (int) – Radius for the mask
brz (float) – Binarizing for shrinking mask (Default: 0.35)
thmi (float) – Minimum threshold for sharp edges; keep only the sharpest edges
thma (float) – Maximum threshold for sharp edges; keep only the sharpest edges
thlimi (float) – Minimum limiting threshold; includes more edges than previously, but ignores simple details
thlima (float) – Maximum limiting threshold; includes more edges than previously, but ignores simple details
edgemask (vs.VideoNode | None) – Edgemask to use. If None, uses
clip.std.Prewitt()
(Default: None).
- Return type
vs.VideoNode
- Returns
Halo mask
- lvsfunc.mask.mt_xxpand_multi(clip, sw=1, sh=None, mode=Shapes.ELLIPSE, start=0, m__imum=vapoursynth.core.std.Maximum, planes=[0, 1, 2], **m_params)
Mask expanding/inpanding function written by Zastin.
Performs multiple Minimums/Maximums.
- Return type
List
[VideoNode
]
- lvsfunc.mask.range_mask(clip, rad=2, radc=0)
Min/max mask with separate luma/chroma radii.
rad/radc are the luma/chroma equivalent of gradfun3’s “mask” parameter. The way gradfun3’s mask works is on an 8 bit scale, with rounded dithering of high depth input. As such, when following this filter with a Binarize, use the following conversion steps based on input:
8 bit = Binarize(2) or Binarize(thr_det)
16 bit = Binarize(384) or Binarize((thr_det - 0.5) * 256)
floats = Binarize(0.005859375) or Binarize((thr_det - 0.5) / 256)
When radii are equal to 1, this filter becomes identical to mt_edge(“min/max”, 0, 255, 0, 255).
- Parameters
clip (
VideoNode
) – Input cliprad (
int
) – Depth in pixels of the detail/edge maskingradc (
int
) – Chroma equivalent torad
- Return type
VideoNode
- Returns
Range mask