SHOW:
|
|
- or go back to the newest paste.
1 | function GreyCenteredToMask_dhh(clip input) { | |
2 | input.Levels(128, 1, 255, 0, 255, false) | |
3 | one = last | |
4 | input.Levels(0, 1, 128, 255, 0, false) | |
5 | two = last | |
6 | Overlay(one, two, mode="lighten") | |
7 | } | |
8 | ||
9 | ||
10 | function FastLineDarkenMOD3_dhh( clip c, int "strength", int "prot", int "luma_cap", int "threshold", int "thinning") | |
11 | { | |
12 | ## parameters ## | |
13 | str = string(default(strength, 50) /128.) | |
14 | lum = string(default(luma_cap, 191)) | |
15 | protection = default(prot,5) | |
16 | thr = string(default(threshold, 4)) | |
17 | thinning = default(thinning,0) | |
18 | thn = string(thinning /16.) | |
19 | ||
20 | ## filtering ## | |
21 | exin = c.mt_expand(thy=255/(protection+1)).mt_inpand() | |
22 | diff = mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x") | |
23 | 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. | |
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") | |
25 | thin = mt_lutxy(c.mt_expand(),diff,yexpr="x y 127 - "+str+" 1 + * +") | |
26 | ||
27 | (thinning == 0) ? thick : mt_merge(thin,thick,linemask,y=3) | |
28 | return mergechroma(c)} | |
29 | ||
30 | ||
31 | function Camembert_dhh(clip input) { | |
32 | ||
33 | input | |
34 | SmoothUV(3,200,false) | |
35 | Overlay(last, Blur(1).Blur(1), mode="difference") | |
36 | GreyCenteredToMask_dhh().greyscale() | |
37 | Levels(0, 1, 115, 0, 255, false) | |
38 | mask1 = last | |
39 | Blur(1) | |
40 | Levels(0, 0.4, 64, 0, 255, false) | |
41 | mask = last | |
42 | Blur(1).Blur(1) | |
43 | Levels(0, 1, 30, 0, 255, false).Blur(1) | |
44 | mask2 = last | |
45 | return (mask2) | |
46 | } | |
47 | ||
48 | function Camembert_dhhMod(clip input) | |
49 | { | |
50 | EM1=input.Camembert_dhh() | |
51 | 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() | |
52 | return mt_logic(EM1, EM2, "and") | |
53 | } | |
54 | ||
55 | Function EMask_dhh(clip i, int mode, int trh) | |
56 | { | |
57 | e_mask = mode == 1 ? mt_makediff(i.blur(1.58).blur(1.58),i).mt_binarize(threshold=trh).mt_inflate().mt_inflate() : | |
58 | \ mode == 2 ? mt_logic(i.mt_binarize(105,upper=true).mt_expand(),i.mt_binarize(110,upper=false).mt_expand(),"and").mt_deflate() : | |
59 | \ 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() | |
60 | return e_mask | |
61 | } | |
62 | ||
63 | Function DR_Radius_dhh(clip i, int dr_rad, int count) | |
64 | { | |
65 | return count > dr_rad ? i : DR_Radius_dhh(i.mt_expand(), dr_rad, count+1) | |
66 | } | |
67 | ||
68 | Function DeHaloHmod(clip input, int "Radius", int "Str", bool "Maska", bool "strong", int "mode", int "thr") | |
69 | { | |
70 | strong = Default(strong, true) | |
71 | Maska = Default(Maska, false) | |
72 | DR_Radius_dhh = Default(Radius, 2) | |
73 | DR_Str = Default(Str, 3) | |
74 | mode = Default(mode, 3) | |
75 | threshold = Default(thr, 140) | |
76 | ||
77 | EM1 = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold) | |
78 | ||
79 | RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius_dhh,0).mt_inflate() | |
80 | ||
81 | DeRinging = mt_Merge(input.TBilateral(DR_Str,5,0.9,0.9,5,5,0.7), input, EM1) | |
82 | DeRinging = Maska ? DeRinging.Invert() : DeRinging | |
83 | ||
84 | return mt_Merge(input, DeRinging, RM2) | |
85 | } | |
86 | ||
87 | Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold") | |
88 | { | |
89 | strong = Default(strong, true) | |
90 | Maska = Default(Maska, false) | |
91 | DR_Radius = Default(DR_Radius, 2) | |
92 | DR_Str = Default(DR_Str, 15) | |
93 | mode = Default(mode, 0) | |
94 | - | threshold = Default(threshold, 150) |
94 | + | threshold = Default(threshold, 140) |
95 | ||
96 | EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold) | |
97 | ||
98 | RM=DR_Radius_dhh(EM,DR_Radius,0) | |
99 | DeRinging = input.Deen("a2d", 2, DR_Str , 0, 0, 0, 0, 0) | |
100 | DeRinging = Maska ? DeRinging.Invert() : DeRinging | |
101 | return mt_Merge(input, DeRinging, RM) | |
102 | } |