Advertisement
Guest User

DDComb

a guest
Aug 15th, 2018
208
0
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. ### 2018.08.14 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,chroma=2).Repair(o.vinverse2H(uv=2),9,0) : o.blur(1,0).Vinverse2H(uv=2) : o.vinverse2H(uv=2) : o.separatefields().vinverse2(uv=2).weave()
  19.  
  20.   D1      = strong && avs26 && sisField ? nop() :  mt_makediff(o,clean1)
  21.   D8      = strong && avs26 && sisField ? nop() :  D1.bicubicresize(ox/2-72,oy).blur(1,0).bicubicresize(ox,oy,1,0)
  22.   D9      = strong && avs26 && sisField ? nop() :  mt_lutxy(D1,D8,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  23.   clean1a = strong && avs26 && sisField ? clean1 : clean1.mt_adddiff(D9,U=2,V=2)
  24.   clean1b = strong && avs26 && sisField ? clean1a.aBlur(1, blurv=0,chroma=2).Repair(clean1a,5,0) : clean1a.frfun7(1.01,8,0).MergeChroma(clean1a)
  25.   clean1b = sisField && !(clean1b.IsFieldBased()) ? c.getparity() ? clean1b.AssumeBFF().AssumeFieldBased().AssumeTFF() : clean1b.AssumeTFF().AssumeFieldBased().AssumeBFF() : clean1b
  26.  
  27.   allD    = mt_makediff(o,clean1b,u=128,v=128)
  28.   shrpD   = mt_makediff(clean1b,clean1b.removegrain(20))
  29.   DD      = shrpD.repair(allD,13,0).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(blur=1, blurv=0, chroma=2).Repair(clean1a,9,0) : clean1a.Blur(1,0).Blur(1,sisField ? 0 : 1),averagewithwhiterPixel=avs26,averagewithwhiterPixelrep=6) : 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 ? strong && avs26 ? DD.aBlur(1, blurv=0,chroma=2).Repair(DD,9,0) : DD.sbrH() : DD.sbr(),U=2,V=2)
  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 ? avs26 ? YToUV(clean2a.utoy8(),clean2a.vtoy8(),clean2a.converttoy8().checkmate(tthr2=0)) : clean2a.checkmate(tthr2=0) : clean2a
  38.   clean2b = static ? sisField ? clean2b.separatefields() : clean2b : nop()
  39.   clean2b = static ? sisField ? clean2b.Repair(c,9,0) : 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.   clean2b = static ? sisField && strong && avs26 ? clean2b.aBlur(blur=1,blurv=0,chroma=2).Repair(clean2b,5,0) : clean2b : nop()
  42.   clean3c = static ? mt_merge(clean1c,clean2b,clean2m,U=2,V=2) : clean1c
  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=o.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")
  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.   Hblur  = clp.sbrH()
  86.   HblurD = mt_MakeDiff(clp,Hblur,U=uv2,V=uv2)
  87.   Hshrp  = mt_LutXY(Hblur,Hblur.mt_convolution("1 2 1","1"),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
  88.   HshrpD = mt_MakeDiff(Hshrp,Hblur,U=uv2,V=uv2)
  89.   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)
  90.   mt_AddDiff(Hblur,HlimD,U=uv,V=uv)
  91.   (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)
  92.   return(last)
  93. }
  94.  
  95. function sbrH(clip o)
  96. {
  97.   rg11=o.mt_convolution("1 2 1","1")
  98.   rg11D=mt_makediff(o,rg11)
  99.   rg11DD=mt_makediff(rg11D,rg11D.mt_convolution("1 2 1","1")).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  100.   o.mt_makediff(rg11DD,U=2,V=2)
  101. }
  102.  
  103.  
  104. # sBlackerPixel by A.SONY, for repairing DeCrawled and dehaloed clip
  105. # v1.54
  106.  
  107. function sBlackerPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade", clip "o2", val "averagewithwhiterPixel", int "averagewithwhiterPixelrep")
  108. {
  109. maxdiff   = default(maxdiff,              32)
  110. thr       = default(thr,                  40)
  111. mdifffade = default(mdifffade, maxdiff*3/2.0)
  112. linflate  = default(linflate,           true)
  113.  
  114. doaverage = defined(averagewithwhiterPixel)
  115. whiterPixelclip = doaverage ? isclip(averagewithwhiterPixel) ? averagewithwhiterPixel : isstring(averagewithwhiterPixel) ? eval(averagewithwhiterPixel) : swhiterPixel(o, filtered, maxdiff, thr, linflate, mdifffade, o2) : nop()
  116.  
  117. 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 ?")
  118.                         \                     : 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()
  119.  
  120. mdifffade!=0 ? Mt_Merge(defined(o2) ? o2 : o,filtered, linflate ? dpmask.mt_inflate(155) : dpmask,U=2,V=2) : \
  121.                VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y > y "+string(thr)+" > & x y - "+string(maxdiff)+" < & y x ?",U=2,V=2)
  122.                \                     : o.mt_lutxy(filtered,"x y > y "+string(thr)+" scalef > & x y - "+string(maxdiff)+" scalef < & y x ?",U=2,V=2)
  123. doaverage ? defined(averagewithwhiterPixelrep) ? mt_average(last, whiterPixelclip.Repair(o,averagewithwhiterPixelrep,-1), u=2, v=2) : mt_average(last, whiterPixelclip, u=2, v=2) : last
  124. }
  125.  
  126. # swhiterPixel by A.SONY
  127. # v1.2
  128.  
  129. function swhiterPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade", clip "o2")
  130. {
  131. maxdiff   = default(maxdiff,              32)
  132. thr       = default(thr,                 215)
  133. mdifffade = default(mdifffade, maxdiff*3/2.0)
  134. linflate  = default(linflate,           true)
  135.  
  136. 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 ?")
  137.                         \                     : 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 ?") : nop()
  138.  
  139. mdifffade!=0 ? Mt_Merge(defined(o2) ? o2 : o,filtered, linflate ? wpmask.mt_inflate(155) : wpmask,U=2,V=2) : \
  140.                VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y < y "+string(thr)+" < & y x - "+string(maxdiff)+" > & y x ?",U=2,V=2)
  141.                \                     : o.mt_lutxy(filtered,"x y < y "+string(thr)+" scalef < & y x - "+string(maxdiff)+" scalef > & y x ?",U=2,V=2)
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement