SHARE
TWEET

DDComb

a guest Jul 21st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### ONLY FOR PROGRESSIVE VIDEO or Field Based
  2. ### Based on Didée's script
  3. ### 2019.07.22 mod
  4. Function DDComb(clip c, float "band", bool "static", bool "strong", bool "checkmate")
  5. {
  6.   avs26    = !(VersionNumber() < 2.60)
  7.   band     = default(band,0)
  8.   static   = default(static,false)
  9.   strong   = default(strong,false)
  10.   usecheck = default(checkmate,!strong)
  11.   sisField = c.IsFieldBased()
  12.   c
  13.   borders = sisField ? weave().bicubicresize(width()/2,height()/2).separatefields().bicubicresize(width()+8,height()) : bicubicresize(width()/2,height()/2).bicubicresize(width()+8,height())
  14.   stackhorizontal(borders.crop(0,0,4,0),last,borders.crop(width()+4,0,0,0))
  15.  
  16.   o=last ox=o.width() oy=o.height()
  17.  
  18.   clean1  = sisField ? strong ? avs26 ? o.aBlur(2, blurv=0).Repair(o.vinverse2H(uv=1, pass=strong ? 5 : 1),9,-1) : o.blur(1,0).Vinverse2H(uv=1, pass=strong ? 6 : 1) : o.vinverse2H(uv=1) : o.separatefields().vinverse2(uv=1).weave()
  19.  
  20.   D1      = mt_makediff(o,clean1)
  21.   D8      = avs26 ? YToUV(D1.utoy8(),D1.vtoy8(),D1.converttoy8().bicubicresize(ox/2-72,oy).blur(1,0).bicubicresize(ox,oy,1,0)) : D1.bicubicresize(ox/2-72,oy).blur(1,0).bicubicresize(ox,oy,1,0)
  22.   D9      = mt_lutxy(D1,D8,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  23.   clean1a = clean1.mt_adddiff(D9,U=2,V=2)
  24.   clean1b = strong && avs26 && sisField ? sBlackerPixel(o=clean1a,filtered=clean1a.aBlur(1, blurv=0).Repair(clean1a,9,-1),mdifffade=128,averagewithwhiterPixel=true) : clean1a.frfun7(1.01,8,0)
  25.   clean1b = sisField && !(clean1b.IsFieldBased()) ? c.getparity() ? clean1b.AssumeBFF().AssumeFieldBased().AssumeTFF() : clean1b.AssumeTFF().AssumeFieldBased().AssumeBFF() : clean1b
  26.  
  27.   allD    = mt_makediff(o,clean1b)
  28.   shrpD   = mt_makediff(clean1b,clean1b.removegrain(20,-1))
  29.   DD      = shrpD.repair(allD,13,-1).mt_lutxy(shrpD,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  30.   clean1b = strong ? sBlackerPixel(o=clean1b, filtered=sisField && avs26 ? clean1a.aBlur(1, blurv=0).Repair(clean1a,9,-1) : clean1a.Blur(1,0).Blur(1,sisField ? 0 : 1),averagewithwhiterPixel=avs26,averagewithwhiterPixelrep=2,deeponly=!usecheck) : clean1b
  31.   clean1c = clean1b.mt_lutxy(clean1a,"x 3 + y < x 2 + x y < x 1 + x 3 - y > x 2 - x y > x 1 - x ? ? ? ?",U=2,V=2)
  32.                 \.mt_adddiff(sisField ? DD.sbrH(strong ? 3 : 1) : DD.sbr())
  33.  
  34.   clean1c = clean1c.crop(4,0,-4,0,true)
  35.   dirty2c = static ? sisField ? c.weave() : c : nop()
  36.   clean2a = static ? dirty2c.tcomb(mode=0) : nop()
  37.   clean2b = static && usecheck ? clean2a.checkmate(tthr2=0) : clean2a
  38.   clean2b = static ? sisField ? clean2b.separatefields() : clean2b : nop()
  39.   clean2b = static ? sisField ? clean2b.Repair(clean1c,9,-1) : clean2b : nop()
  40.   clean2m = static ? mt_lutxy(c,clean2b,"x y == 0 x 64 <= x y - abs 32 < 255 x y - abs 48 < 255 255 48 / x y - abs * - 0 ? ? y 40 > x y > & x y - 16 >= 255 x y - 16 < ? 255 16 / x y - * 0 ? 0 ? ? ?").mt_inflate(155,155) : nop()
  41.   clean3c = static ? mt_merge(clean1c,clean2b,clean2m,U=1,V=1) : clean1c
  42.   clean3c = clean3c.mergechroma(c)
  43.   output  = band != 0 ? clean3c.gradfun3(thr=band,smode=2) : clean3c
  44.   return output
  45.   #--- end of script ---#
  46. }
  47. #######################################################
  48.  
  49. #--- Helper functions below ---#
  50.  
  51. function Vinverse2(clip clp, float "sstr", int "amnt", int "uv")
  52. {
  53.   uv   = default(uv,3)
  54.   sstr = default(sstr,2.7)
  55.   amnt = default(amnt,255)
  56.   uv2  = (uv==2) ? 1 : uv
  57.   STR  = string(sstr)
  58.   AMN  = string(amnt)
  59.   vblur  = clp.sbrV()
  60.   vblurD = mt_MakeDiff(clp,vblur,U=uv2,V=uv2)
  61.   Vshrp  = mt_LutXY(vblur,vblur.mt_convolution("1","1 2 1"),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
  62.   VshrpD = mt_MakeDiff(Vshrp,vblur,U=uv2,V=uv2)
  63.   VlimD  = mt_LutXY(VshrpD,VblurD,expr="x 128 - y 128 - * 0 < x 128 - abs y 128 - abs < x y ? 128 - 0.25 * 128 + x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
  64.   mt_AddDiff(Vblur,VlimD,U=uv,V=uv)
  65.   (amnt>254) ? last : (amnt==0) ? clp : mt_LutXY(clp,last,expr="x "+AMN+" + y < x "+AMN+" + x "+AMN+" - y > x "+AMN+" - y ? ?",U=uv,V=uv)
  66.   return(last)
  67. }
  68.  
  69. function sbrV(clip o)
  70. {
  71.   rg11=mt_convolution("1","1 2 1")
  72.   rg11D=mt_makediff(o,rg11)
  73.   rg11DD=mt_makediff(rg11D,rg11D.mt_convolution("1","1 2 1")).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  74.   o.mt_makediff(rg11DD,U=2,V=2)
  75. }
  76.  
  77. function Vinverse2H(clip clp, float "sstr", int "amnt", int "uv", int "pass")
  78. {
  79.   uv   = default(uv,3)
  80.   sstr = default(sstr,2.7)
  81.   amnt = default(amnt,255)
  82.   uv2  = (uv==2) ? 1 : uv
  83.   STR  = string(sstr)
  84.   AMN  = string(amnt)
  85.   pass = Default(pass, 1)
  86.   Hblur  = clp.sbrH(pass)
  87.   HblurD = mt_MakeDiff(clp,Hblur,U=uv2,V=uv2)
  88.   Hshrp  = mt_LutXY(Hblur,spasses(Hblur, pass, """mt_convolution("1 2 1","1")"""),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
  89.   HshrpD = mt_MakeDiff(Hshrp,Hblur,U=uv2,V=uv2)
  90.   HlimD  = mt_LutXY(HshrpD,HblurD,expr="x 128 - y 128 - * 0 < x 128 - abs y 128 - abs < x y ? 128 - 0.25 * 128 + x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
  91.   mt_AddDiff(Hblur,HlimD,U=uv,V=uv)
  92.   (amnt>254) ? last : (amnt==0) ? clp : mt_LutXY(clp,last,expr="x "+AMN+" + y < x "+AMN+" + x "+AMN+" - y > x "+AMN+" - y ? ?",U=uv,V=uv)
  93.   return(last)
  94. }
  95.  
  96. function sbrH(clip o, int "pass")
  97. {
  98.   pass = Default(pass, 1)
  99.   rg11=spasses(o, pass, """mt_convolution("1 2 1","1")""")
  100.   rg11D=mt_makediff(o,rg11)
  101.   rg11DD=mt_makediff(rg11D,spasses(rg11D, pass, """mt_convolution("1 2 1","1")""")).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  102.   o.mt_makediff(rg11DD,U=2,V=2)
  103. }
  104.  
  105. Function spasses(clip i, int "pass", string "filter")
  106. {
  107. return pass > 0 ? eval("spasses(i." + filter + ", pass-1, filter)") : i
  108. }
  109.  
  110. # sBlackerPixel by A.SONY, for repairing DeCrawled and dehaloed clip
  111. # v1.56
  112.  
  113. function sBlackerPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade", clip "o2", val "averagewithwhiterPixel", int "averagewithwhiterPixelrep", bool "deeponly")
  114. {
  115. maxdiff   = default(maxdiff,              32)
  116. thr       = default(thr,                  40)
  117. mdifffade = default(mdifffade, maxdiff*3/2.0) #should be more than the maxdiff
  118. linflate  = default(linflate,           true)
  119. whidorep  = defined(averagewithwhiterPixelrep)
  120.  
  121. Assert((defined(o) && defined(filtered)), "both o clip and filtered clip are needed")
  122.  
  123. doaverage = defined(averagewithwhiterPixel)
  124. whiterPixelclip = doaverage ? isclip(averagewithwhiterPixel) ? averagewithwhiterPixel : isstring(averagewithwhiterPixel) ? eval(averagewithwhiterPixel) : swhiterPixel(o, filtered, maxdiff, 255-thr, linflate, mdifffade, o2, deeponly) : nop()
  125.  
  126. dpmask = mdifffade!=0 ? VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"y "+string(thr)+" > x y > & x y - "+string(maxdiff)+" < 255 x y - "+string(mdifffade)+" < ? 255 255 "+string(mdifffade)+" / x y - * - 0 ? 0 ?")
  127.                         \                     : o.mt_lutxy(filtered,"y "+string(thr)+" scalef > x y > & x y - "+string(maxdiff)+" scalef < range_max x y - "+string(mdifffade)+" scalef < ? range_max range_max "+string(mdifffade)+" scalef / x y - * - 0 ? 0 ?") : nop()
  128.  
  129. mdifffade!=0 ? Mt_Merge(defined(o2) ? o2 : o,filtered, linflate ? dpmask.mt_inflate(155) : dpmask,U=2,V=2) : \
  130.                VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y > y "+string(thr)+" > & x y - "+string(maxdiff)+" < & y x ?",U=2,V=2)
  131.                \                     : o.mt_lutxy(filtered,"x y > y "+string(thr)+" scalef > & x y - "+string(maxdiff)+" scalef < & y x ?",U=2,V=2)
  132. doaverage ? whidorep ? mt_average(last, whiterPixelclip.Repair(o,averagewithwhiterPixelrep,-1), u=2, v=2) : mt_average(last, whiterPixelclip, u=2, v=2) : last
  133. }
  134.  
  135. # swhiterPixel by A.SONY
  136. # v1.26
  137.  
  138. function swhiterPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade", clip "o2", bool "deeponly")
  139. {
  140. maxdiff   = default(maxdiff,              32)
  141. thr       = default(thr,                 215)
  142. mdifffade = default(mdifffade, maxdiff*3/2.0) #should be more than the maxdiff
  143. linflate  = default(linflate,           true)
  144. deeponly  = default(deeponly,          false)
  145.  
  146. Assert((defined(o) && defined(filtered)), "both o clip and filtered clip are needed")
  147.  
  148. wpmask = mdifffade!=0 ? VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"y "+string(thr)+" < x y < & y x - "+string(maxdiff)+" > 255 y x - "+string(mdifffade)+" > ? 255 255 "+string(mdifffade)+" / y x - * - 0 ? 0 ?")
  149.                         \                     : o.mt_lutxy(filtered,"y "+string(thr)+" scalef < x y < & y x - "+string(maxdiff)+" scalef > range_max y x - "+string(mdifffade)+" scalef > ? range_max range_max "+string(mdifffade)+" scalef / y x - * - 0 ? 0 ?",use_expr=2) : nop()
  150.  
  151. wpmask = mdifffade!=0 && deeponly ? wpmask.mt_invert().mt_expand(155).mt_inpand(155).mt_invert() : wpmask
  152.  
  153. mdifffade!=0 ? Mt_Merge(defined(o2) ? o2 : o,filtered, linflate ? wpmask.mt_inflate(155) : wpmask,U=2,V=2) : \
  154.                VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y < y "+string(thr)+" < & y x - "+string(maxdiff)+" > & y x ?",U=2,V=2)
  155.                \                     : o.mt_lutxy(filtered,"x y < y "+string(thr)+" scalef < & y x - "+string(maxdiff)+" scalef > & y x ?",use_expr=2,U=2,V=2)
  156. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top