Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def denoise_but_actually_dont(clip, degrain_tr=3, degrain_thsad=100,
- comp_tr=3, comp_thsad=200, comp_blur=11,
- recalc_thsad=None, truemotion=False, search=4, trymany=False,
- sigma=0, radius1=1, psample=0,
- mask=None, repair=13,
- sharp=False, sharp_str=1, sharp_pre=0, sharp_merge=1, sharp_limit=None,
- limit_thr=0, limit_elast=2.,
- blur_rad=None, median_rad=None, sbr_rad=None, rgmode=21,
- s0=1., c=0.0625):
- core = vs.core
- comp_tr = min(comp_tr, 12)
- tr = max(degrain_tr, comp_tr)
- isHD = 1 if clip.width >= 1100 or clip.height >= 600 else 0
- recalc_thsad = fallback(recalc_thsad, [degrain_thsad / x for x in (2,4,8)])
- if isinstance(recalc_thsad, list):
- while len(recalc_thsad) < 3:
- recalc_thsad.append(recalc_thsad[-1])
- else:
- recalc_thsad = [recalc_thsad] * 3
- blur_rad = fallback(blur_rad, [1,2][isHD])
- median_rad = fallback(median_rad, [1,2][isHD])
- sbr_rad = fallback(sbr_rad, [1,2][isHD])
- clipsf = core.resize.Point(clip, format=vs.GRAYS)
- clip = core.resize.Point(clip, format=vs.GRAY16)
- if mask:
- if isinstance(mask, list):
- while len(mask) < 2:
- mask.append(mask[-1])
- else:
- mask = [mask] * 2
- emask = core.std.Prewitt(clipsf)
- emask = amp_mask(emask, mask[0], mask[1])
- emask = core.rgsf.RemoveGrain(emask, [11,20][isHD])
- if sigma:
- smooth = mvf.BM3D(clip, sigma=sigma, radius1=radius1, psample=psample)
- else:
- smooth = dfttest_prefilter(clip)
- pre_b = core.std.Convolution(clip, [1]*9) if 1 < blur_rad < 2 else core.rgvs.RemoveGrain(clip, 11)
- if blur_rad >= 2:
- for _ in range(blur_rad - 1):
- pre_b = core.std.Convolution(pre_b, [1]*9)
- pre_m = core.std.Median(clip) if median_rad is 1 else core.ctmf.CTMF(clip, radius=median_rad)
- pre_s = haf.sbr(clip, r=sbr_rad)
- pre_r = core.rgvs.RemoveGrain(clip, rgmode)
- pre = [MMFilter([clip, smooth, pre_b])]
- pre+= [MMFilter([clip, pre[0], pre_m])]
- pre+= [MMFilter([clip, pre[1], pre_s])]
- pre+= [MMFilter([clip, pre[2], pre_r])]
- pre = [DLRmod(preclip, s0, c) for preclip in pre]
- asup = core.mvsf.Super(pre[3], 16, 16, 1, 0, rfilter=4)
- rsupa= core.mvsf.Super(pre[2], 16, 16, 1, 1)
- rsupb= core.mvsf.Super(pre[1], 16, 16, 1, 1)
- rsupc= core.mvsf.Super(pre[0], 16, 16, 1, 1)
- dsup = core.mvsf.Super(clipsf, 16, 16, 1, 1)
- vec = mv.Analyse(asup, blksize=16, search=search, tr=tr, truemotion=truemotion, overlap=8, trymany=trymany)
- vec = mv.Recalculate(rsupa, vec, thsad=recalc_thsad[0], blksize=8, search=search, truemotion=truemotion, overlap=4, tr=tr, interleave=False)
- vec = mv.Recalculate(rsupb, vec, thsad=recalc_thsad[1], blksize=4, search=search, truemotion=truemotion, overlap=2, tr=tr, interleave=False)
- vec = mv.Recalculate(rsupb, vec, thsad=recalc_thsad[2], blksize=4, search=search, truemotion=truemotion, overlap=2, tr=tr, interleave=False)
- degrain_vec_start = tr - degrain_tr
- degrain_vec_end = degrain_tr * 2 + degrain_vec_start
- degrain_vec = vec[degrain_vec_start:degrain_vec_end]
- clean = mv.DegrainN(clipsf, dsup, degrain_vec, tr=degrain_tr, thsad=degrain_thsad)
- if sigma:
- clean = MMFilter([clipsf, clean, core.resize.Point(bm3d, format=vs.GRAYS)])
- if sharp:
- clean = csharpmod(clean, clipsf, strength=sharp_str, prefilter=sharp_pre, darkened_merge=sharp_merge, brightened_merge=sharp_merge, darkening_limit=sharp_limit, brightening_limit=sharp_limit)
- if limit_thr:
- clean = LimitFilter(clean, clipsf, thr=limit_thr/219, elast=elast, mode=0)
- if mask:
- clean = core.std.MaskedMerge(clean, clipsf, emask)
- if repair:
- clean = core.rgsf.Repair(clean, clipsf, repair)
- grain = core.std.MakeDiff(clipsf, clean)
- gsup = core.mvsf.Super(grain, 16, 16, 1, 1)
- comp_vec_start = tr - comp_tr
- comp_vec_end = comp_tr * 2 + comp_vec_start
- comp_vec = vec[comp_vec_start:comp_vec_end]
- comp = mv.Compensate(grain, gsup, comp_vec, thsad=comp_thsad, tr=comp_tr, interleave=False)
- vlen = comp_tr * 2 + 1
- abc = [f' {x} ' for x in 'xyzabcdefghijklmnopqrstuv'][:vlen]
- add = [' + '] * (vlen - 1)
- count = vlen
- if comp_blur in (11, 12):
- count = 2
- for x in range(1, vlen - 1):
- weight = 1 << ( comp_tr - abs( x - comp_tr ) )
- abc[x] += f' {weight} * '
- count += weight
- divisor = [f' {count} / ']
- expr = ''.join(abc + add + divisor)
- grain = core.std.Expr(comp, expr)
- stable = core.std.MergeDiff(clean, grain)
- return MMFilter([clip,clean,stable])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement