View difference between Paste ID: LtaC7ECe and j8ik4yr1
SHOW: | | - or go back to the newest paste.
1
# DeHaloHmod 27 8 2014 http://forum.doom9.org/showthread.php?p=1675762#post1675762
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-
str        = string(default(strength, 50) /128.)
13+
14-
lum 	   = string(default(luma_cap, 191))
14+
15
str        = string(default(strength, 48) /128.)
16-
thr 	   = string(default(threshold, 4))
16+
lum        = string(default(luma_cap, 191))
17
protection = default(prot,5)
18-
thn 	   = string(thinning /16.)
18+
thr        = string(default(threshold, 4))
19
thinning   = default(thinning,0)
20
thn        = string(thinning /16.)
21-
exin	= c.mt_expand(thy=255/(protection+1)).mt_inpand()
21+
 
22-
diff 	= mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x")
22+
23
exin    = c.mt_expand(thy=255/(protection+1)).mt_inpand()
24-
thick 	= mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x")
24+
diff    = mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x",u=2, v=2)
25-
thin 	= mt_lutxy(c.mt_expand(),diff,yexpr="x y 127 - "+str+" 1 + * +")
25+
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-
(thinning == 0) ? thick : mt_merge(thin,thick,linemask,y=3)
27+
thin    = mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2)
28-
return mergechroma(c)}
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)
58
{
59
e_mask = mode == 1 ? mt_makediff(i.blur(1.58).blur(1.58),i).mt_binarize(threshold=trh).mt_inflate().mt_inflate() :
60
     \   mode == 2 ? mt_logic(i.mt_binarize(105,upper=true).mt_expand(),i.mt_binarize(110,upper=false).mt_expand(),"and").mt_deflate() :
61
     \   mode == 3 ? 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()
62
return e_mask
63
}
64
65
Function DR_Radius_dhh(clip i, int dr_rad, int count)
66
{
67
return count > dr_rad ? i : DR_Radius_dhh(i.mt_expand(), dr_rad, count+1)
68
}
69
70
Function DeHaloHmod(clip input, int "Radius", int "Str", bool "Maska", bool "strong", int "mode", int "thr")
71
{
72
 strong     = Default(strong, true)
73
 Maska      = Default(Maska, false)
74
 DR_Radius_dhh  = Default(Radius, 2)
75
 DR_Str     = Default(Str, 3)
76
 mode       = Default(mode, 3)
77
 threshold  = Default(thr, 140)
78
79
 EM1 = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
80
81
 RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius_dhh,0).mt_inflate()
82
83
 DeRinging  = mt_Merge(input.TBilateral(DR_Str,5,0.9,0.9,5,5,0.7), input, EM1)
84
 DeRinging = Maska ?  DeRinging.Invert() : DeRinging
85
86
return mt_Merge(input, DeRinging, RM2)
87
}
88
89
Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold")
90
{
91
 strong     = Default(strong, true)
92
 Maska      = Default(Maska, false)
93
 DR_Radius  = Default(DR_Radius, 2)
94
 DR_Str     = Default(DR_Str, 15)
95
 mode       = Default(mode, 0)
96
 threshold  = Default(threshold, 140)
97
98
 EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
99
100
 RM=DR_Radius_dhh(EM,DR_Radius,0)
101
 DeRinging  = input.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0)
102
 DeRinging = Maska ?  DeRinging.Invert() : DeRinging
103
return mt_Merge(input, DeRinging, RM)
104
}