View difference between Paste ID: DCwkWPi2 and YcYDV3e9
SHOW: | | - or go back to the newest paste.
1
### ONLY FOR PROGRESSIVE VIDEO or Field Based
2
### Based on Didée's script
3-
### 2016.11.17 mod
3+
### 2016.11.18 mod
4
Function DDComb(clip c, float "band", bool "static", bool "strong")
5
{
6
  band     = default(band,0)
7
  static   = default(static,false)
8
  strong   = default(strong,false)
9
  c
10
  borders = bicubicresize(width()/2,height()/2).bicubicresize(width()+8,height())
11
  stackhorizontal(borders.crop(0,0,4,0),last,borders.crop(width()+4,0,0,0))
12
13
  o=last ox=o.width() oy=o.height()
14
15
  clean1  = c.IsFieldBased() ? o.vinverse2() : o.separatefields().vinverse2().weave()
16
 
17
  D1      = mt_makediff(o,clean1)
18
  D8      = D1.bicubicresize(ox/2-72,oy).blur(1,0).bicubicresize(ox,oy,1,0)
19
  D9      = mt_lutxy(D1,D8,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
20
  clean1a = clean1.mt_adddiff(D9,U=2,V=2)
21
  clean1b = clean1a.frfun7(1.01,8,1)
22
  clean1b = c.IsFieldBased() && !(clean1b.IsFieldBased()) ? c.getparity() ? clean1b.AssumeBFF().AssumeFieldBased().AssumeTFF() : clean1b.AssumeTFF().AssumeFieldBased().AssumeBFF() : clean1b
23
24
  allD    = mt_makediff(o,clean1b,u=128,v=128)
25
  shrpD   = mt_makediff(clean1b,clean1b.removegrain(20))
26
  DD      = shrpD.repair(allD,13,0).mt_lutxy(shrpD,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
27
  clean1b = strong ? sBlackerPixel(o=clean1b, filtered=clean1a.Blur(1,0).Blur(1,c.IsFieldBased() ? 0 : 1)) : clean1b
28
  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)
29
                \.mt_adddiff(c.IsFieldBased() ? DD.sbrV() : DD.sbr(),U=2,V=2)
30
31
  clean1c = clean1c.crop(4,0,-4,0,true)
32
  clean2c = static ? clean1c.IsFieldBased() ? clean1c.weave() : clean1c : nop()
33
  clean1d = static ? clean2c.tcomb(mode=0).checkmate(tthr2=0) : nop()
34
  clean1d = static ? clean1c.IsFieldBased() ? clean1d.separatefields() : clean1d : nop()
35
  clean1m = static ? mt_lutxy(clean1d,clean1c,"x y - 2 - 0 > 255 y x - 2 - 0 > 255 0 ? ?") : nop()
36
  clean1c = static ? mt_merge(clean1c,clean1d,clean1m,U=2,V=2) : clean1c
37
  output  = band != 0 ? clean1c.gradfun3(thr=band,smode=2) : clean1c
38
  return output
39
  #--- end of script ---#
40
}
41
#######################################################
42
 
43
#--- Helper functions below ---#
44
 
45
function Vinverse2(clip clp, float "sstr", int "amnt", int "uv")
46
{
47
  uv   = default(uv,3)
48
  sstr = default(sstr,2.7)
49
  amnt = default(amnt,255)
50
  uv2  = (uv==2) ? 1 : uv
51
  STR  = string(sstr)
52
  AMN  = string(amnt)
53
  vblur  = clp.sbrV()
54
  vblurD = mt_MakeDiff(clp,vblur,U=uv2,V=uv2)
55
  Vshrp  = mt_LutXY(vblur,vblur.mt_convolution("1","1 2 1"),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
56
  VshrpD = mt_MakeDiff(Vshrp,vblur,U=uv2,V=uv2)
57
  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)
58
  mt_AddDiff(Vblur,VlimD,U=uv,V=uv)
59
  (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)
60
  return(last)
61
}
62
63
function sbrV(clip o)
64
{
65
  rg11=o.mt_convolution("1","1 2 1")
66
  rg11D=mt_makediff(o,rg11)
67
  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 ? ?")
68
  o.mt_makediff(rg11DD,U=2,V=2)
69
}
70
71
72
# sBlackerPixel by A.SONY, for repairing DeCrawled and dehaloed clip
73
74
function sBlackerPixel(clip "o", clip "filtered", int "maxdiff", int "thr", bool "linflate")
75
{
76
maxdiff = default(maxdiff,   32)
77
thr     = default(thr,       40)
78
linflate= default(linflate,true)
79
maxdiff2=maxdiff*3/2
80
81-
linflate ? Mt_Merge(o,filtered,o.mt_lutxy(filtered,"y "+string(thr)+" > x y > x y - "+string(maxdiff)+" < & 255 x y - "+string(maxdiff2)+" < ? 255 255 "+string(maxdiff2)+" / x y - * - 0 ? 0 ?").mt_inflate(155,155),U=2,V=2) : \
81+
linflate ? Mt_Merge(o,filtered,o.mt_lutxy(filtered,"y "+string(thr)+" > x y > & x y - "+string(maxdiff)+" < 255 x y - "+string(maxdiff2)+" < ? 255 255 "+string(maxdiff2)+" / x y - * - 0 ? 0 ?").mt_inflate(155,155),U=2,V=2) : \
82
           o.mt_lutxy(filtered,"x y > y "+string(thr)+" > & x y - "+string(maxdiff)+" < & y x ?",U=2,V=2)
83
}