lvsfunc.deblock

Deblocking functions and wrappers.

lvsfunc.deblock.dpir(clip[, strength, mode, ...])

DPIR, or Plug-and-Play Image Restoration with Deep Denoiser Prior, is a denoise and deblocking neural network.

lvsfunc.deblock.autodb_dpir(clip[, ...])

Rewrite of fvsfunc.AutoDeblock that uses vspdir instead of dfttest to deblock.

lvsfunc.deblock.autodb_dpir(clip, edgevalue=24, strs=[10, 50, 75], thrs=[(1.5, 2.0, 2.0), (3.0, 4.5, 4.5), (5.5, 7.0, 7.0)], matrix=None, kernel=vskernels.Bicubic, cuda=True, write_props=False, **vsdpir_args)

Rewrite of fvsfunc.AutoDeblock that uses vspdir instead of dfttest to deblock.

This function checks for differences between a frame and an edgemask with some processing done on it, and for differences between the current frame and the next frame. For frames where both thresholds are exceeded, it will perform deblocking at a specified strength. This will ideally be frames that show big temporal and spatial inconsistencies.

Thresholds and calculations are added to the frameprops to use as reference when setting the thresholds.

Keep in mind that dpir is not perfect; it may cause weird, black dots to appear sometimes. If that happens, you can perform a denoise on the original clip (maybe even using dpir’s denoising mode) and grab the brightest pixels from your two clips. That should return a perfectly fine clip.

Thanks Vardë, louis <https://github.com/tomato39>_, Setsugen no ao!

Dependencies:

Parameters
  • clip (vs.VideoNode) – Clip to process.

  • edgevalue (int) – Remove edges from the edgemask that exceed this threshold (higher means more edges removed).

  • strs (Sequence[float]) – A list of DPIR strength values (higher means stronger deblocking). You can pass any arbitrary number of values here. Sane deblocking strengths lie between 1–20 for most regular deblocking. Going higher than 50 is not recommended outside of very extreme cases. The amount of values in strs and thrs need to be equal.

  • thrs (Sequence[Tuple[float, float, float]]) – A list of thresholds, written as [(EdgeValRef, NextFrameDiff, PrevFrameDiff)]. You can pass any arbitrary number of values here. The amount of values in strs and thrs need to be equal.

  • matrix (Matrix | int | None) – Enum for the matrix of the Clip to process. See lvsfunc.types.Matrix for more info. If None, gets matrix from the “_Matrix” prop of the clip unless it’s an RGB clip, in which case it stays as None.

  • kernel (Kernel | str) – py:class:vskernels.Kernel object used for conversions between YUV <-> RGB. This can also be the string name of the kernel (Default: py:class:vskernels.Bicubic(0, 0.5)).

  • cuda (bool) – Use CUDA backend if True, else CPU backend.

  • write_props (bool) – whether to write verbose props.

  • vsdpir_args (Any) – Additional args to pass to lvsfunc.deblock.vsdpir().

Return type

vs.VideoNode

Returns

Deblocked clip with different strengths applied based on the given parameters.

Raises

ValueError – Unequal number of strengths and thrs passed.

lvsfunc.deblock.dpir(clip, strength=10, mode='deblock', matrix=None, cuda=None, i444=False, tiles=None, overlap=8, zones=None, fp16=None, num_streams=1, device_id=0, kernel=vskernels.Bicubic)

DPIR, or Plug-and-Play Image Restoration with Deep Denoiser Prior, is a denoise and deblocking neural network.

You must install vs-mlrt. For more information, see the following links:

Converts to RGB -> runs DPIR -> converts back to original format, and with no subsampling if i444=True. For more information, see the original DPIR repository.

Thanks Setsugen no ao!

Alias for this function is lvsfunc.vsdpir.
Note that this will be deprecated in the future!

Dependencies:

Parameters
  • clip (vs.VideoNode) – Clip to process.

  • strength (SupportsFloat | vs.VideoNode | None) –

    DPIR strength. Sane values lie between 1–10 for mode='deblock', and 1–3 for mode='denoise' Other than a float, you can also pass a clip, either GRAY8 (0-255), or GRAYS (0-+inf).

    For example, you can pass a clip.std.BlankClip(format=vs.GRAYS, color=15.0 / 255)() for a solid strength across the frame, or you can combine various strengths with masks.

    This means you can pass higher strenghts to areas around edges with heavy ringing, and lower in textured/detailed parts, for example.

  • mode (str) – DPIR mode. Valid modes are ‘deblock’ and ‘denoise’.

  • matrix (Matrix | int | None) – Enum for the matrix of the Clip to process. See lvsfunc.types.Matrix for more info. If not specified, gets matrix from the “_Matrix” prop of the clip unless it’s an RGB clip, in which case it stays as None.

  • cuda (bool | Literal['trt'] | None) – Used to select backend. Use CUDA if True, CUDA TensorRT if ‘trt’, else CPU OpenVINO if False. If None, it will detect your system’s capabilities and select the fastest backend.

  • i444 (bool) – Forces the returned clip to be YUV444PS instead of the input clip’s format.

  • tiles (int | Tuple[int, int] | None) – Can either be an int, specifying the number of tiles the image will be split into for processing, or a tuple for manually specifying the width/height of the singular tiles.

  • overlap (int | Tuple[int, int] | None) – Number of pixels in each direction for padding the tiles. Useful for, when using tiled processing, you’re having clear boundaries between tiles. To disable, set None or 0. Default: 8px.

  • zones (List[Tuple[Range | List[Range] | None, SupportsFloat | vs.VideoNode | None]] | None) – A mapping to zone the DPIR strength so you don’t have to call it multiple times. The key should be a float / VideoNode (a normalised mask, for example) or None to passthrough the Clip to process. The values should be a range that will be passed to replace_ranges

  • fp16 (bool | None) – Represent the clip with 16f tensors instead of 32f for a speedup, but it’s useless— and may even harm performance—when enabled with a device that doesn’t support it.

  • num_streams (int) – Number of concurrent CUDA streams to use. Increase if GPU isn’t getting saturated.

  • device_id (int) – Specifies the GPU device id to use.

  • kernel (Kernel | str) – py:class:vskernels.Kernel object used for conversions between YUV <-> RGB. This can also be the string name of the kernel (Default: py:class:vskernels.Bicubic(0, 0.5)).

Return type

vs.VideoNode

Returns

Deblocked or denoised clip in either the given clip’s format or YUV444PS.

Raises
  • ModuleNotFoundError – Dependencies are missing.

  • TypeError – Invalid mode is given.

  • ValueErrorstrength is a VideoNode, but not GRAY8 or GRAYS.

  • ValueErrorstrength is a VideoNode, but of a different length than the input clip.

  • TypeErrorstrength is not a typing.SupportsFloat or VideoNode.