Guest User

FixChromaBleedingMod

a guest
Feb 6th, 2014
379
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # FixChromaBleedingMod v1.2
  2.  
  3. Function FixChromaBleedingMod (clip input, int "Shift", float "thr", float "strength", bool "f", float "opacity") {
  4.  
  5.   Shift = default ( Shift,       -4 )
  6.   thr   = default ( thr,       4.0 )
  7.   stre = default ( strength,       0.8 )
  8.   f =  default ( f,       true )
  9.   opacity = default ( opacity,       1 )
  10.  
  11.   # prepare to work on the V channel and reduce to speed up and filter noise
  12.   areaf = input.tweak(sat=thr).VtoY.ReduceBy2
  13.   area = input.tweak(sat=thr).VtoY.Blur(1)
  14.  
  15.   # select and normalize both extremes of the scale
  16.   red = f ? areaf.Levels(255,1.0,255,255,0) : area.Levels(255,1.0,255,255,0)
  17.   blue = f ? areaf.Levels(0,1.0,0,0,255) : area.Levels(0,1.0,0,0,255)
  18.  
  19.   # merge both masks
  20.   maskc = MergeLuma(red, blue, 0.5).Levels(250,1.0,250,255,0)
  21.  
  22.   # expand to cover beyond the bleeding areas and shift to compensate the resizing
  23.    maskc = maskc.mt_edge("0 0 0 1 0 0 0 0 0", 0,255,0,255).mt_edge("1 1 1 1 1 1 0 0 0", 0,255,0,255)
  24.  
  25.   # back to full size and binarize (also a trick to expand)
  26.   maskc = maskc.BilinearResize(Width(input),Height(input)).Levels(10,1.0,10,0,255)
  27.  
  28.   # prepare a version of the image that has its chroma shifted and less saturated
  29.   input_c = input.ChromaShift(C=Shift).tweak(sat=stre)
  30.  
  31.   # combine both images using the mask
  32.   return input.overlay(input_c,mask=maskc,mode="blend",opacity=opacity)
  33. }
RAW Paste Data