lvsfunc.mask
Masks are used to limit where filtering takes place, and how strong the filtering is applied. lvsfunc offers a couple of masks, and they’re often used internally in other functions.
All masks come limited by default, so you don’t need to worry about illegal ranges messing with your masked output.
|
Positional bounding box. |
|
Deferred masking interface. |
|
Create a detail mask to be used during denoising and/or debanding. |
|
Detail mask aimed at preserving as much detail as possible. |
|
Min/max mask with separate luma/chroma radii. |
- class lvsfunc.mask.BoundingBox(pos, size)
Bases:
object
Positional bounding box.
Basically kagefunc.squaremask, but can be configured and then deferred.
Uses Position + Size, like provided by GIMP’s rectangle selection tool.
- Parameters
pos (
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 (
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.
- pos: Position
- size: 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.
- Raises
ValueError – Bound exceeds clip size.
- class lvsfunc.mask.DeferredMask(ranges=None, bound=None, *, blur=False, refframes=None)
Bases:
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 (BoundingBox | tuple[tuple[int, int], tuple[int, int]] | None) – A
lvsfunc.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
lvsfunc.types.FrameRangesN()
.
- Raises
ValueError – Reference frame and ranges mismatch.
- ranges: vstools.FrameRangesN
- blur: bool
- bound: lvsfunc.mask.BoundingBox | None
- refframes: list[int | None]
- get_mask(clip, ref)
Get the bounded mask.
- Parameters
clip (
VideoNode
) – Source.ref (
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)
Create 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
) – Clip to process.sigma (
Optional
[float
]) – Sigma for Bilateral for pre-blurring (Default: False).rad (
int
) – The luma equivalent of gradfun3’s “mask” parameter.brz_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=vstools.core.std.Prewitt, rg_mode=17)
Detail mask aimed at preserving as much detail as possible.
This mask will catch a whole lot of stuff, including noise and grain.
- Parameters
clip (
VideoNode
) – Clip to process.sigma (
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 detection.rg_mode (
Union
[int
,Sequence
[int
]]) – Removegrain mode performed on the final output.
- Return type
VideoNode
- Returns
Detail mask.
- 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
) – Clip to process.rad (
int
) – Depth in pixels of the detail/edge masking.radc (
int
) – Chroma equivalent torad
.
- Return type
VideoNode
- Returns
FrameRangesN mask.