Advertisement
tp7

Less bad TempLinearApproximateMC

tp7
Nov 6th, 2014
295
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import vapoursynth as vs
  2.  
  3. def TempLinearApproximateMC(clip, meclip = None, radius = 2, planes = None, subpel = 4, subpelinterp = None, dct = None, refine = False, blocksize = None,
  4.     overlap = None, search = None, searchparam = None, pelsearch = None, chromamotion = True, truemotion = True, _lambda = None, lsad = None, pnew = None,
  5.     plevel = None, globalmotion = True, thsad = None, thscd1 = None, thscd2 = None, badrange = None, isse = None, gamma = None):
  6.     #-------------------------------------------------------------------------------------------------------------------------------------
  7.    
  8.     core = vs.get_core()
  9.    
  10.     if not isinstance(clip, vs.VideoNode) or clip.format.id != vs.YUV420P8:
  11.         raise ValueError('MCDenoise.TempLinearApproximate: Input format must be YUV420P8.')
  12.     if not isinstance(radius, int) or radius < 1:
  13.         raise ValueError("MCDenoise.TempLinearApproximate: 'radius' must be larger than 1.")
  14.        
  15.     #-------------------------------------------------------------------------------------------------------------------------------------
  16.    
  17.     tla_arguments = {"radius": radius, "planes": planes, "gamma": gamma}
  18.     super_arguments = {"pel": subpel, "sharp": subpelinterp}
  19.     compensate_arguments = {"thsad":thsad, "thscd1":thscd1, "thscd2":thscd2}
  20.     recalculate_arguments = {"dct":dct, "chroma":chromamotion, "search":search,  "searchparam":searchparam, "truemotion":truemotion, "lambda":_lambda}
  21.     analyze_arguments = {
  22.         "dct":dct,
  23.         "chroma":chromamotion,
  24.         "search":search,
  25.         "searchparam":searchparam,
  26.         "truemotion":truemotion,
  27.         "lambda":_lambda,  
  28.         "pelsearch":pelsearch,
  29.         "blksize":blocksize if not refine else None,
  30.         "overlap":overlap if not refine else None,
  31.         "lsad":lsad,
  32.         "pnew":pnew,
  33.         "plevel":plevel,
  34.         "globalmotion":globalmotion,
  35.         "badrange":badrange
  36.         "isse":isse
  37.     }
  38.    
  39.    
  40.     input_super = core.mv.Super(clip, **super_arguments)
  41.     me_super = input_super if not meclip else core.mv.Super(meclip, **super_arguments)
  42.        
  43.     #-------------------------------------------------------------------------------------------------------------------------------------
  44.     def compensate(isb, delta):
  45.         if refine:
  46.             vector = core.mv.Analyse(me_super, isb=isb, delta=delta, blksize=32, overlap=16, **analyze_arguments)
  47.             vector = core.mv.Recalculate(me_super, vector, blksize=16, overlap=8, **recalculate_arguments)
  48.             vector = core.mv.Recalculate(me_super, vector, blksize=8, overlap=4, **recalculate_arguments)
  49.             vector = core.mv.Recalculate(me_super, vector, blksize=4, overlap=2, **recalculate_arguments)
  50.         else:
  51.             vector = core.mv.Analyse(me_super, isb=isb, delta=delta, **analyze_arguments)
  52.         return core.mv.Compensate(clip, input_super, vector, **compensate_arguments)
  53.  
  54.     compensate_back = [compensate(True, i) for i in range(radius, 0, -1)]
  55.     compensate_forward = [compensate(False, i) for i in range(1, radius+1)]
  56.    
  57.     sequence = compensate_back + [clip] + compensate_forward
  58.     interleaved = core.std.Interleave(sequence)        
  59.     filtered = core.tla.TempLinearApproximate(interleaved, **tla_arguments)
  60.    
  61.     return core.std.SelectEvery(filtered, radius * 2 + 1, radius)
Advertisement
RAW Paste Data Copied
Advertisement