Zastin

eedi3/nnedi3 limited AA thing (VS)

Aug 22nd, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. from vapoursynth import core
  2. import vapoursynth as vs
  3. import vsTAAmbk as taa
  4. import mvsfunc as mvf
  5.  
  6. def aa(clip, str=1, thr=10, elast=2, alpha=0.25, beta=0.5, gamma=40, nrad=2, mdis=20, nsize=3, nns=3, qual=2, **args):
  7.     """ eedi3-based anti-aliasing filter. Stronger than plain nnedi3 but not as much oversmoothing as eedi3, with some limiting for good measure
  8.        
  9.        How it works: Uses a eedi3-treated clip and nnedi3-treated clip
  10.                      The filtered difference of the eedi3 clip is clamped to the diff of the nnedi3 clip + strength
  11.                      The resulting clip is then limited with mvsfunc's LimitFilter to protect areas of small, high contrast detail
  12.                      
  13.        Parameters: str      - Upper ceiling for eedi3 filtering strength relative to nnedi3, to which all pixels are clamped to (scaled to 8 bit)
  14.                               The expression is as follows:
  15.                                   if nnedi3 and eedi3 have an opposite effect (one brighter and one darker than input clip)
  16.                                       return input pixel
  17.                                   else
  18.                                       eedi3 = min(eedi3, nnedi3 + str)
  19.                                       eedi3 = max(eedi3, nnedi3 - str)
  20.                                       return eedi3
  21.                    thr      - Final limiting of anti-aliased clip (LimitFilter parameter)
  22.                               Set to 0 to disable
  23.                    elast    - Another LimitFilter parameter
  24.                    the rest - eedi3 and nnedi3 parameters; see relevant filter documentation for more information
  25.                    
  26.        Most of taa's arguments should work, like masking, repair, etc. They're applied to the eedi3 clip only.
  27.    """
  28.    
  29.     bits = clip.format.bits_per_sample - 8
  30.     str *= 1 >> bits
  31.    
  32.     clipy = mvf.GetPlane(clip)
  33.    
  34.     strong = taa.TAAmbk(clipy, aatype='Eedi3', alpha=alpha, beta=beta, gamma=gamma, nrad=nrad, mdis=mdis, **args)
  35.     weak = taa.TAAmbk(clipy, aatype='Nnedi3', nsize=nsize, nns=nns, qual=qual, mtype=0)
  36.    
  37.     aa = core.std.Expr([strong, weak, clipy], 'x z - y z - * 0 < y x y {l} + min y {l} - max ?'.format(l=str))
  38.    
  39.     if thr > 0:
  40.         aa = mvf.LimitFilter(aa, clipy, thr=thr, elast=elast)
  41.    
  42.     if clip.format.num_planes > 1:
  43.         aa = core.std.ShufflePlanes([aa, clip], [0,1,2], vs.YUV)
  44.        
  45.     return aa
Add Comment
Please, Sign In to add comment