SHOW:
|
|
- or go back to the newest paste.
| 1 | # DeHalo_alpha with high bit support, need masktools 2.2.17 or up in avs26 and avs+ | |
| 2 | - | # 2019.07.22 |
| 2 | + | # 2019.08.06 |
| 3 | ||
| 4 | function DeHalo_alpha_mt(clip input, float "rx", float "ry", float "darkstr", float "brightstr", float "lowsens", float "highsens", float "ss", bool "cs", int "search_rade", int "search_radi") | |
| 5 | {
| |
| 6 | sre = default( search_rade, 1 ) | |
| 7 | sri = default( search_radi, sre ) | |
| 8 | input | |
| 9 | DeHalo_alpha_2BD(rx, ry, darkstr, brightstr, lowsens, highsens, ss, cs, sre, sri) | |
| 10 | } | |
| 11 | ||
| 12 | function DeHalo_alpha(clip input, float "rx", float "ry", float "darkstr", float "brightstr", float "lowsens", float "highsens", float "ss", bool "cs", int "search_rade", int "search_radi") | |
| 13 | {
| |
| 14 | input | |
| 15 | DeHalo_alpha_mt(rx, ry, darkstr, brightstr, lowsens, highsens, ss, cs, search_rade, search_radi) | |
| 16 | } | |
| 17 | ||
| 18 | function m4_dham(float x) {
| |
| 19 | nx=VersionNumber() < 2.6 ? x<16?16:int(round(x/4.0)*4) : round(x) | |
| 20 | return(nx) | |
| 21 | } | |
| 22 | ||
| 23 | # modified dehalo_alpha: here with increased search-radius for validation | |
| 24 | ||
| 25 | function DeHalo_alpha_2BD(clip input, float "rx", float "ry", float "darkstr", float "brightstr", float "lowsens", float "highsens", float "ss", bool "cs", int "search_rade", int "search_radi") | |
| 26 | {
| |
| 27 | rx = default( rx, 2.0 ) | |
| 28 | ry = default( ry, 2.0 ) | |
| 29 | darkstr = default( darkstr, 1.0 ) | |
| 30 | brightstr = default( brightstr, 1.0 ) | |
| 31 | lowsens = default( lowsens, 50 ) | |
| 32 | highsens = default( highsens, 50 ) | |
| 33 | ss = default( ss, 1.5 ) | |
| 34 | cs = default( cs, false ) | |
| 35 | sre = default( search_rade, max(m4_dham(max(rx,ry)),3) ) | |
| 36 | sri = default( search_radi, sre ) | |
| 37 | ||
| 38 | sisphbd = AvsPlusVersionNumber > 2294 | |
| 39 | ||
| 40 | sislumaonly = sisphbd ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8() | |
| 41 | ||
| 42 | clp = sislumaonly ? input : sisphbd ? input.converttoy() : input.converttoy8() | |
| 43 | ||
| 44 | LOS = string(lowsens) | |
| 45 | HIS = string(highsens/100.0) | |
| 46 | DRK = string(darkstr) | |
| 47 | BRT = string(brightstr) | |
| 48 | ox = clp.width() | |
| 49 | oy = clp.height() | |
| 50 | ||
| 51 | halos = clp.bicubicresize(m4_dham(ox/rx),m4_dham(oy/ry)).bicubicresize(ox,oy,1,0) | |
| 52 | - | are = sre==1 && sri==1 ? clp .mt_edge(mode="min/max", thY1=0, thY2=255) : VersionNumber() < 2.6 ? mt_lutxy(clp .srdha2e(sre,1),clp .srdha2i(sri,1),"x y -",U=1,V=1) : mt_lutxy(clp .srdha2e(sre,1),clp .srdha2i(sri,1),"x y -",use_expr=3,U=1,V=1) |
| 52 | + | are = sre==1 && sri==1 ? clp .mt_edge(mode="min/max", thY1=0, thY2=255) : VersionNumber() < 2.6 ? mt_lutxy(clp .srdha2e(sre,1),clp .srdha2i(sri,1),"x y -",U=1,V=1) : mt_lutxy(clp .srdha2e(sre,1),clp .srdha2i(sri,1),"x y -",use_expr=3,clamp_float=true,U=1,V=1) |
| 53 | - | ugly = sre==1 && sri==1 ? halos.mt_edge(mode="min/max", thY1=0, thY2=255) : VersionNumber() < 2.6 ? mt_lutxy(halos.srdha2e(sre,1),halos.srdha2i(sri,1),"x y -",U=1,V=1) : mt_lutxy(halos.srdha2e(sre,1),halos.srdha2i(sri,1),"x y -",use_expr=3,U=1,V=1) |
| 53 | + | ugly = sre==1 && sri==1 ? halos.mt_edge(mode="min/max", thY1=0, thY2=255) : VersionNumber() < 2.6 ? mt_lutxy(halos.srdha2e(sre,1),halos.srdha2i(sri,1),"x y -",U=1,V=1) : mt_lutxy(halos.srdha2e(sre,1),halos.srdha2i(sri,1),"x y -",use_expr=3,clamp_float=true,U=1,V=1) |
| 54 | so = VersionNumber() < 2.6 ? mt_lutxy( ugly, are, "y x - y 0.001 + / 255 * "+LOS+" - y 256 + 512 / "+HIS+" + *" ) | |
| 55 | \ : mt_lutxy( ugly, are, "y x - y 0.001 + / range_max * "+LOS+" scalef - y range_size + 512 scalef / "+HIS+" + *", scale_inputs="floatf",use_expr=1 ) | |
| 56 | lets = mt_merge(halos,clp,so,U=1,V=1) | |
| 57 | remove = (ss==1.0) ? clp.repair(lets,1,0) | |
| 58 | \ : clp.lanczosresize(m4_dham(ox*ss),m4_dham(oy*ss)) | |
| 59 | \ .mt_logic(lets.mt_expand(U=1,V=1).bicubicresize(m4_dham(ox*ss),m4_dham(oy*ss)),"min",U=2,V=2) | |
| 60 | \ .mt_logic(lets.mt_inpand(U=1,V=1).bicubicresize(m4_dham(ox*ss),m4_dham(oy*ss)),"max",U=2,V=2) | |
| 61 | \ .lanczosresize(ox,oy) | |
| 62 | them = VersionNumber() < 2.6 ? mt_lutxy(clp,remove,"x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",U=2,V=2) | |
| 63 | \ : mt_lutxy(clp,remove,"x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",clamp_float=true,use_expr=1,U=2,V=2) | |
| 64 | ||
| 65 | bb = cs ? them.removegrain(11) : nop() | |
| 66 | xD = cs ? mt_makediff(bb,bb.repair(bb.repair(bb.medianblur(2,-333,-333),1),1)) : nop() | |
| 67 | xD = cs ? VersionNumber() < 2.6 ? xD.mt_lut("x 128 - 2.49 * 128 +") : xD.mt_lut("x range_half - 2.49 * range_half +",clamp_float=true,use_expr=1) : xD
| |
| 68 | xDD = cs ? VersionNumber() < 2.6 ? mt_lutxy(xD,mt_makediff(clp,them),"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?") | |
| 69 | \ : mt_lutxy(xD,mt_makediff(clp,them),"x range_half - y range_half - * 0 < range_half x range_half - abs y range_half - abs < x y ? ?",use_expr=1) : nop() | |
| 70 | them = cs ? them.mt_adddiff(xDD,U=2,V=2) : them | |
| 71 | ||
| 72 | them = sislumaonly ? them : sisphbd ? CombinePlanes(them,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),them) | |
| 73 | ||
| 74 | return( them ) | |
| 75 | } | |
| 76 | ||
| 77 | Function srdha2e(clip i, int dr_rad, int count) | |
| 78 | {
| |
| 79 | return count > dr_rad ? i : srdha2e(i.mt_expand(), dr_rad, count+1) | |
| 80 | } | |
| 81 | ||
| 82 | Function srdha2i(clip i, int dr_rad, int count) | |
| 83 | {
| |
| 84 | return count > dr_rad ? i : srdha2i(i.mt_inpand(), dr_rad, count+1) | |
| 85 | } |