View difference between Paste ID: YsPU3GJx and mqGYTh3C
SHOW: | | - or go back to the newest paste.
1-
# DeHaloHmod 20 09 2016
1+
# DeHaloHmod 29 09 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")
74
{
75
 usedeen    = Default(usedeen, false)
76
 smooth     = Default(smooth, false)
77
 strong     = Default(strong, true)
78
 Maska      = Default(Maska, false)
79
 analog     = Default(analog, false)
80
 dirty      = Default(dirty, false)
81
 DR_Radius  = Default(Radius, dirty ? 6 : smooth ? 4 : 2)
82
 DR_Str     = Default(Str, smooth ? 5 : usedeen ? 15 : 3)
83
 mode       = Default(mode, usedeen ? 0 : 3)
84
 threshold  = Default(thr, smooth ? 2250 : 140)
85-
 anime      = Default(anime, usedeen ? false : true)
85+
 anime      = Default(anime, mode != 3 ? false : true)
86
 pel2       = Default(pel2, false)
87
 maskpel2   = Default(maskpel2, false)
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(darkstr=0.2,brightstr=0.8).yahr2(dirty ? 8 : 16).TBilateral(DR_Str,5,0.9,0.9,5,5,0.7,chroma=false) : usedeen ? oclip.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0) : oclip.TBilateral(DR_Str,5,0.9,0.9,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
 EM1 = 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)
99
100
 EM1 = maskpel2 ? EM1.PointResize(input.Width(),input.Height()) : EM1
101
102
 hfl = pel2 && (maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
103
104
 RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate()
105
106
 DeRinging = anime ? mt_Merge(hfl, input, smooth ? EM1.mt_inflate(155,155) : EM1) : hfl
107
 DeRinging = Maska ?  DeRinging.Invert() : DeRinging
108
109
return mt_Merge(input, DeRinging, RM2, u=2, v=2)
110
}
111
112
Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold")
113
{
114
 strong     = Default(strong, true)
115
 Maska      = Default(Maska, false)
116
 DR_Radius  = Default(DR_Radius, 2)
117
 DR_Str     = Default(DR_Str, 15)
118
 mode       = Default(mode, 0)
119
 threshold  = Default(threshold, 140)
120
121
 EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
122
123
 RM=DR_Radius_dhh(EM,DR_Radius,0)
124
 DeRinging  = input.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0)
125
 DeRinging = Maska ?  DeRinging.Invert() : DeRinging
126
return mt_Merge(input, DeRinging, RM)
127
}