Advertisement
Zastin

Min/Max Filter (Minblur)

Jan 5th, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. from vapoursynth import core
  2.  
  3. def MMFilter(clips, mode='min', planes=None):
  4.     """ Min/Max Filter
  5.        For "clips" supply an array of 3: a source clip and 2 filtered clips
  6.        When mode='max' - Take the largest filtered difference, or the mean difference if one is darker and the other brighter
  7.        When mode='min' - Take the smallest filtered difference, or the source pixel if one is darker and the other brighter
  8.    """
  9.     planes = list(range(clips[0].format.num_planes)) if planes is None else [planes] if isinstance(planes, int) else planes
  10.     expr = 'x y - x z - * 0 < {} x y - abs x z - abs < {} ? ?'.format('y z + 2 /' if mode=='max' else 'x', 'z y' if mode=='max' else 'y z')
  11.     expr = [expr if i in planes else '' for i in range(clips[0].format.num_planes)]
  12.     return core.std.Expr(clips, expr)
  13.  
  14. # Example (MinBlur):
  15. # clips = [clip, clip.rgvs.Removegrain(11), clip.std.Median()]
  16. # MMFilter(clips, 'min')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement