Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th November 2022, 23:25   #1  |  Link
STJAM
Registered User
 
Join Date: Oct 2012
Posts: 20
ZZZ Denoise

Several years ago when I transitioned from Avisynth to Vapoursynth I missed several of the scripts that I sometimes used like zzz denoise. I tried to adapt ZZZ Denoise but was never happy with the result. I dug it back up because someone in Avisynth usage was looking for a Masked Spatial-Temporal denoiser and this came to mind although this is probably not what they had in mind. Has someone have a similar script or possibly improve on what is below.

def zzz_denoise (clip, sigma=16, mask=False, scale=30, thsad=200):
core = vs.get_core()
filter = core.ttmpsm.TTempSmooth(clip)
pre = core.rgvs.RemoveGrain(filter, 12)
super = clip.mv.Super(levels=1)
super_a = pre.mv.Super()
fwd_vect_3 = core.mv.Analyse(super_a, isb=False, delta=3, overlap=4)
fwd_vect_2 = core.mv.Analyse(super_a, isb=False, delta=2, overlap=4)
fwd_vect_1 = core.mv.Analyse(super_a, isb=False, delta=1, overlap=4)
bck_vect_1 = core.mv.Analyse(super_a, isb=True, delta=1, overlap=4)
bck_vect_2 = core.mv.Analyse(super_a, isb=True, delta=2, overlap=4)
bck_vect_3 = core.mv.Analyse(super_a, isb=True, delta=3, overlap=4)
fwd_comp_2 = core.mv.Compensate(clip, super, fwd_vect_2, thsad=thsad)
fwd_comp_1 = core.mv.Compensate(clip, super, fwd_vect_1, thsad=thsad)
bck_comp_1 = core.mv.Compensate(clip, super, bck_vect_1, thsad=thsad)
bck_comp_2 = core.mv.Compensate(clip, super, bck_vect_2, thsad=thsad)
interleaved = core.std.Interleave([fwd_comp_2, fwd_comp_1, clip, bck_comp_1, bck_comp_2])
c_dft = core.dfttest.DFTTest(interleaved, sigma=sigma)
c_dft = core.std.SelectEvery(c_dft,5,2)
c_deg = core.mv.Degrain3 (clip, super, bck_vect_1, fwd_vect_1, bck_vect_2, fwd_vect_2, bck_vect_3, fwd_vect_3, thsad=thsad)
edge_mask = core.std.Prewitt(c_deg, scale=scale)
edge_mask = hf.mt_expand_multi(edge_mask)
#edge_mask = hf.mt_inflate_multi(edge_mask)
#edge_mask = core.std.Maximum(edge_mask)
v_em = core.std.ShufflePlanes(edge_mask,0,vs.GRAY)
c_hyb = core.std.MaskedMerge(c_dft, c_deg, mask=edge_mask, planes=[0,1,2])
if mask:
return v_em
else:
return c_hyb
STJAM is offline   Reply With Quote
Old 15th November 2022, 16:53   #2  |  Link
Setsugen no ao
Registered User
 
Join Date: Dec 2021
Posts: 3
Code:
from typing import Any

from vsdenoise import MVTools
from vsmask.util import expand
from vsrgtools import RemoveGrainMode, removegrain
from vstools import core, get_y, vs


def zzz_denoise(
    clip: vs.VideoNode, sigma: int = 16,
    tr: int = 3, thSAD: int = 200, overlap: int = 4, refine: int = 0,
    scale: int = 30, show_mask: bool = False, **kwargs: Any
) -> vs.VideoNode:
    if 'prefilter' not in kwargs:
        kwargs.update(prefilter=removegrain(clip.ttmpsm.TTempSmooth(), RemoveGrainMode.OPP_CLIP_AVG_FAST))

    mv = MVTools(clip, tr, refine, overlap=overlap, **kwargs)

    c_dft = mv.compensate(core.dfttest.DFTTest, thSAD, sigma=sigma, tbsize=mv.tr + 2)
    c_deg = mv.degrain(thSAD)

    edge_mask = get_y(c_deg).std.Prewitt(scale=scale)
    edge_mask = expand(edge_mask, 1)

    if show_mask:
        return edge_mask

    return c_dft.std.MaskedMerge(c_deg, edge_mask)
Setsugen no ao is offline   Reply With Quote
Old 19th November 2022, 15:17   #3  |  Link
STJAM
Registered User
 
Join Date: Oct 2012
Posts: 20
Python exception: cannot import name 'KwargsNotNone' from 'vstools'
STJAM is offline   Reply With Quote
Old 19th November 2022, 18:02   #4  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 321
It looks like vstools is a package that needs to be installed.
In your script it is not a problem to not to use it:
instead of:
Code:
from vstools import core, get_y, vs
use:
Code:
import vapoursynth as vs
from vapoursynth import core
and instead of:
Code:
edge_mask = get_y(c_deg).std.Prewitt(scale=scale)
use:
Code:
edge_mask = c_deg.std.SplitPlanes()[0].std.Prewitt(scale=scale)
SplitPlanes() was introduced lately, if having old vapoursynth version use:
Code:
edge_mask = c_deg.std.ShufflePlanes(planes=[0], colorfamily=vs.GRAY).std.Prewitt(scale=scale)
_Al_ is offline   Reply With Quote
Old 19th November 2022, 19:51   #5  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
vsdenoise, vsmask, vsrgtools, vstools are all stuff from https://github.com/Irrational-Encoding-Wizardry that would need to be installed.
(didn't check what are the dependencies of those)
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 19th November 2022, 21:06   #6  |  Link
STJAM
Registered User
 
Join Date: Oct 2012
Posts: 20
Thanks, _AI_ you provided me with what I needed to fix my original script and thank you Selur. I thought I had installed the required packages but I guess not. I am new to pip and I presume I did something wrong.

Last edited by STJAM; 19th November 2022 at 22:37.
STJAM is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 13:05.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.