View difference between Paste ID: tA7aHtYP and 4xv7u9te
SHOW: | | - or go back to the newest paste.
1-
# DeHaloHmod 07 10 2016
1+
# DeHaloHmod 11 11 2016
2
3
function GreyCenteredToMask_dhh(clip input) {
4
input.Levels(128, 1, 255, 0, 255, false)
5
one = last
6
input.Levels(0, 1, 128, 255, 0, false)
7
two = last
8
Overlay(one, two, mode="lighten")
9
}
10
11
12
function FastLineDarkenMOD3_dhh( clip c, int "strength", int "prot", int "luma_cap", int "threshold", int "thinning") 
13
{
14
## parameters ##
15
str        = string(default(strength, 48) /128.)
16
lum        = string(default(luma_cap, 191))
17
protection = default(prot,5)
18
thr        = string(default(threshold, 4))
19
thinning   = default(thinning,0)
20
thn        = string(thinning /16.)
21
 
22
## filtering ##
23
exin    = c.mt_expand(thy=255/(protection+1)).mt_inpand()
24
diff    = mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x")
25
linemask= mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").mt_convolution("1 1 1","1 1 1",y=3,u=0,v=0)#".RemoveGrain(20,-1)" gives a little speed boost.
26
thick   = mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x",u=2, v=2)
27
thin    = mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2)
28
 
29
return (thinning == 0) ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2)
30
}
31
32
33
function Camembert_dhh(clip input) {
34
35
input
36
SmoothUV(3,200,false)
37
Overlay(last, Blur(1).Blur(1), mode="difference")
38
GreyCenteredToMask_dhh().greyscale()
39
Levels(0, 1, 115, 0, 255, false)
40
mask1 = last
41
Blur(1)
42
Levels(0, 0.4, 64, 0, 255, false)
43
mask = last
44
Blur(1).Blur(1)
45
Levels(0, 1, 30, 0, 255, false).Blur(1)
46
mask2 = last
47
return (mask2)
48
}
49
50
function Camembert_dhhMod(clip input)
51
{
52
 EM1=input.Camembert_dhh()
53
 EM2=input.mt_edge(mode="min/max", thY1=1, thY2=255, thC1=10, thC2=10, chroma="process").mt_inflate().blur(1.5).blur(1.5).invert()
54
 return mt_logic(EM1, EM2, "and")
55
}
56
57
Function EMask_dhh(clip i, int "mode", int "trh", bool "analog", float "trh2")
58
{
59
analog     = Default(analog, false)
60
trh2       = Default(trh2, 170)
61
e_mask = mode == 1 ? mt_makediff(i.blur(1.58).blur(1.58),i).mt_binarize(threshold=trh).mt_inflate().mt_inflate() :
62
     \   mode == 2 ? mt_logic(i.mt_binarize(105,upper=true).mt_expand(),i.mt_binarize(110,upper=false).mt_expand(),"and").mt_deflate() :
63
     \   mode == 3 ? analog ? mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh, i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2).mt_lut("x "+String(trh2/2.46)+" < 255 x "+String(trh2)+" > 0 255 x "+String(trh2/2.46)+" - 255 "+String(trh2)+" "+String(trh2/2.46)+" - / * - ? ?",u=1,v=1)) :
64
                            \ mt_merge(i.mt_edge(mode="min/max", thY1=255, thY2=255), i.Camembert_dhh, i.FastLineDarkenMOD3_dhh(trh).blur(0.5).FastLineDarkenMOD3_dhh(250,1,250,-2).mt_binarize(70, mode="0 255")) : NOP()
65
return e_mask
66
}
67
68
Function DR_Radius_dhh(clip i, int dr_rad, int count)
69
{
70
return count > dr_rad ? i : DR_Radius_dhh(i.mt_expand(), dr_rad, count+1)
71
}
72
73
Function DeHaloHmod(clip input, int "Radius", int "Str", bool "Maska", bool "strong", int "mode", int "thr", string "exdehalo", bool "analog", bool "dirty", bool "smooth", bool "anime", bool "pel2", bool "usedeen", bool "maskpel2", float "thr2", val "extmask")
74
{
75
 usedeen    = Default(usedeen, false)
76
 pel2       = Default(pel2, false)
77
 maskpel2   = Default(maskpel2, false)
78
 smooth     = Default(smooth, false)
79
 strong     = Default(strong, true)
80
 Maska      = Default(Maska, false)
81
 analog     = Default(analog, false)
82
 dirty      = Default(dirty, false)
83
 DR_Radius  = Default(Radius, dirty ? 6 : smooth || maskpel2 ? 4 : 2)
84-
 DR_Str     = Default(Str, smooth ? 5 : usedeen ? pel2 ? 40 : 15 : pel2 ? 7 : 3)
84+
 DR_Str     = Default(Str, usedeen ? pel2 ? 40 : 15 : pel2 ? 7 : smooth ? 5 : 3)
85
 mode       = Default(mode, usedeen ? 0 : 3)
86
 threshold  = Default(thr, smooth ? mode==1 ? 1 : 2250 : 140)
87
 anime      = Default(anime, mode != 3 ? false : true)
88
 thr2       = Default(thr2, smooth ? 170 : threshold/1.5)
89
90
 oclip = pel2 ? input.nnedi3_rpow2(rfactor=2) : input
91
 hfl = defined(exdehalo) ? eval("oclip." + exdehalo) : smooth ? oclip.DeHalo_alpha_mt(rx=pel2 ? 3 : 2,ry=pel2 ? 3 : 2,darkstr=0.2,brightstr=0.8).yahr2(dirty ? pel2 ? 12 : 8 : pel2 ? 24 : 16).TBilateral(DR_Str,5,pel2 ? 1.4 : 0.9,0.9,pel2 ? 7 : 5,5,0.7,chroma=false) : usedeen ? oclip.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0) : oclip.TBilateral(DR_Str,5,pel2 ? 1.4 : 0.9,0.9,pel2 ? 7 : 5,5,0.7,chroma=false)
92
 hfl = pel2 && !(maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
93
94
 cm  = dirty ? hfl : input
95
96
 cm  = !(dirty && pel2) && maskpel2 ? cm.nnedi3_rpow2(rfactor=2) : cm
97
98
 extmask = defined(extmask) ? isclip(extmask) ? extmask : Eval("cm." + extmask) : undefined()
99
100
 EM1 = defined(extmask) ? extmask : mode == 0 ? (strong ? Camembert_dhh(analog ? cm.ColorYUV(autogain=true) : cm) : Camembert_dhhMod(analog ? cm.ColorYUV(autogain=true) : cm)) : EMask_dhh(analog ? cm.ColorYUV(autogain=true) : cm, mode, threshold, analog, thr2)
101
102
 EM1 = maskpel2 ? EM1.PointResize(input.Width(),input.Height()) : EM1
103
104
 hfl = pel2 && (maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
105
106
 RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate()
107
108
 DeRinging = anime ? mt_Merge(hfl, input, smooth ? EM1.mt_inflate(155,155) : EM1) : hfl
109
 DeRinging = Maska ?  DeRinging.Invert() : DeRinging
110
111
return mt_Merge(input, DeRinging, RM2, u=2, v=2)
112
}
113
114
Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold")
115
{
116
 strong     = Default(strong, true)
117
 Maska      = Default(Maska, false)
118
 DR_Radius  = Default(DR_Radius, 2)
119
 DR_Str     = Default(DR_Str, 15)
120
 mode       = Default(mode, 0)
121
 threshold  = Default(threshold, 140)
122
123
 EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
124
125
 RM=DR_Radius_dhh(EM,DR_Radius,0)
126
 DeRinging  = input.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0)
127
 DeRinging = Maska ?  DeRinging.Invert() : DeRinging
128
return mt_Merge(input, DeRinging, RM)
129
}