Advertisement
Guest User

DDComb

a guest
Jun 19th, 2017
89
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. ### 2017.06.20 mod
  4. Function DDComb(clip c, float "band", bool "static", bool "strong", bool "checkmate")
  5. {
  6.   band     = default(band,0)
  7.   static   = default(static,false)
  8.   strong   = default(strong,false)
  9.   usecheck = default(checkmate,!strong)
  10.   c
  11.   borders = bicubicresize(width()/2,height()/2).bicubicresize(width()+8,height())
  12.   stackhorizontal(borders.crop(0,0,4,0),last,borders.crop(width()+4,0,0,0))
  13.  
  14.   o=last ox=o.width() oy=o.height()
  15.  
  16.   clean1  = c.IsFieldBased() ? o.vinverse2(uv=2) : o.separatefields().vinverse2(uv=2).weave()
  17.  
  18.   D1      = mt_makediff(o,clean1)
  19.   D8      = D1.bicubicresize(ox/2-72,oy).blur(1,0).bicubicresize(ox,oy,1,0)
  20.   D9      = mt_lutxy(D1,D8,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  21.   clean1a = clean1.mt_adddiff(D9,U=2,V=2)
  22.   clean1b = clean1a.frfun7(1.01,8,0).MergeChroma(clean1a)
  23.   clean1b = c.IsFieldBased() && !(clean1b.IsFieldBased()) ? c.getparity() ? clean1b.AssumeBFF().AssumeFieldBased().AssumeTFF() : clean1b.AssumeTFF().AssumeFieldBased().AssumeBFF() : clean1b
  24.  
  25.   allD    = mt_makediff(o,clean1b,u=128,v=128)
  26.   shrpD   = mt_makediff(clean1b,clean1b.removegrain(20))
  27.   DD      = shrpD.repair(allD,13,0).mt_lutxy(shrpD,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
  28.   clean1b = strong ? sBlackerPixel(o=clean1b, filtered=clean1a.Blur(1,0).Blur(1,c.IsFieldBased() ? 0 : 1)) : clean1b
  29.   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)
  30.                 \.mt_adddiff(c.IsFieldBased() ? DD.sbrV() : DD.sbr(),U=2,V=2)
  31.  
  32.   clean1c = clean1c.crop(4,0,-4,0,true)
  33.   clean2c = static ? c.IsFieldBased() ? c.weave() : c : nop()
  34.   clean1d = static ? clean2c.tcomb(mode=0) : nop()
  35.   clean1d = static && usecheck ? VersionNumber() < 2.60 ? clean1d.checkmate(tthr2=0) : YToUV(clean1d.utoy8(),clean1d.vtoy8(),clean1d.converttoy8().checkmate(tthr2=0)) : clean1d
  36.   clean1d = static ? c.IsFieldBased() ? clean1d.separatefields() : clean1d : nop()
  37.   clean1m = static ? mt_lutxy(c,clean1d,"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()
  38.   clean1c = static ? mt_merge(clean1c,clean1d,clean1m,U=2,V=2) : clean1c
  39.   output  = band != 0 ? clean1c.gradfun3(thr=band,smode=2) : clean1c
  40.   return output
  41.   #--- end of script ---#
  42. }
  43. #######################################################
  44.  
  45. #--- Helper functions below ---#
  46.  
  47. function Vinverse2(clip clp, float "sstr", int "amnt", int "uv")
  48. {
  49.   uv   = default(uv,3)
  50.   sstr = default(sstr,2.7)
  51.   amnt = default(amnt,255)
  52.   uv2  = (uv==2) ? 1 : uv
  53.   STR  = string(sstr)
  54.   AMN  = string(amnt)
  55.   vblur  = clp.sbrV()
  56.   vblurD = mt_MakeDiff(clp,vblur,U=uv2,V=uv2)
  57.   Vshrp  = mt_LutXY(vblur,vblur.mt_convolution("1","1 2 1"),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
  58.   VshrpD = mt_MakeDiff(Vshrp,vblur,U=uv2,V=uv2)
  59.   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)
  60.   mt_AddDiff(Vblur,VlimD,U=uv,V=uv)
  61.   (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)
  62.   return(last)
  63. }
  64.  
  65. function sbrV(clip o)
  66. {
  67.   rg11=o.mt_convolution("1","1 2 1")
  68.   rg11D=mt_makediff(o,rg11)
  69.   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 ? ?")
  70.   o.mt_makediff(rg11DD,U=2,V=2)
  71. }
  72.  
  73.  
  74. # sBlackerPixel by A.SONY, for repairing DeCrawled and dehaloed clip
  75. # v1.52
  76.  
  77. function sBlackerPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade")
  78. {
  79. maxdiff   = default(maxdiff,              32)
  80. thr       = default(thr,                  40)
  81. mdifffade = default(mdifffade, maxdiff*3/2.0)
  82. linflate  = default(linflate,           true)
  83.  
  84. 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 ?")
  85.                         \                     : 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()
  86.  
  87. mdifffade!=0 ? Mt_Merge(o,filtered, linflate ? dpmask.mt_inflate(155) : dpmask,U=2,V=2) : \
  88.                VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y > y "+string(thr)+" > & x y - "+string(maxdiff)+" < & y x ?",U=2,V=2)
  89.                \                     : o.mt_lutxy(filtered,"x y > y "+string(thr)+" scalef > & x y - "+string(maxdiff)+" scalef < & y x ?",U=2,V=2)
  90. }
  91.  
  92. # swhiterPixel by A.SONY
  93. # v1.1
  94.  
  95. function swhiterPixel(clip "o", clip "filtered", float "maxdiff", float "thr", bool "linflate", float "mdifffade")
  96. {
  97. maxdiff   = default(maxdiff,              32)
  98. thr       = default(thr,                 215)
  99. mdifffade = default(mdifffade, maxdiff*3/2.0)
  100. linflate  = default(linflate,           true)
  101.  
  102. 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 ?")
  103.                         \                     : 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()
  104.  
  105. mdifffade!=0 ? Mt_Merge(o,filtered, linflate ? wpmask.mt_inflate(155) : wpmask,U=2,V=2) : \
  106.                VersionNumber() < 2.6 ? o.mt_lutxy(filtered,"x y < y "+string(thr)+" < & y x - "+string(maxdiff)+" > & y x ?",U=2,V=2)
  107.                \                     : o.mt_lutxy(filtered,"x y < y "+string(thr)+" scalef < & y x - "+string(maxdiff)+" scalef > & y x ?",U=2,V=2)
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement