SHOW:
|
|
- or go back to the newest paste.
| 1 | - | # 2019.07.21 |
| 1 | + | # 2019.07.22 |
| 2 | # Masked_DHA with high bit support, need masktools 2.2.17 or up in avs26 and avs+ | |
| 3 | ||
| 4 | function Masked_DHA(clip input, float "rx", float "ry", float "darkstr", float "brightstr", float "lowsens", float "highsens", float "msk_pull", float "msk_push", float "ss", bool "show_msk", bool "cs", int "search_rade", int "search_radi") | |
| 5 | {
| |
| 6 | rx = default( rx, 2.0 ) | |
| 7 | ry = default( ry, 2.0 ) | |
| 8 | darkstr = default( darkstr, 1.0 ) | |
| 9 | brightstr = default( brightstr, 1.0 ) | |
| 10 | lowsens = default( lowsens, 50 ) | |
| 11 | highsens = default( highsens, 50 ) | |
| 12 | msk_pull = default( msk_pull, 48 ) | |
| 13 | msk_push = default( msk_push, 192 ) | |
| 14 | ss = default( ss, 1.5 ) | |
| 15 | show_msk = default( show_msk, false ) | |
| 16 | cs = default( cs, false ) | |
| 17 | sre = default( search_rade, 1 ) | |
| 18 | sri = default( search_radi, sre ) | |
| 19 | ||
| 20 | rx = max(rx, 1.0) | |
| 21 | ry = max(ry, 1.0) | |
| 22 | darkstr = max(min(darkstr, 1.0), 0.0) | |
| 23 | lowsens = max(min(lowsens, 100), 0) | |
| 24 | highsens = max(min(highsens, 100), 0) | |
| 25 | msk_pull = max(min(msk_pull, 254), 0) | |
| 26 | msk_push = max(min(msk_push, 255), msk_pull + 1) | |
| 27 | ss = max(ss, 1.0) | |
| 28 | ||
| 29 | sisphbd = AvsPlusVersionNumber > 2294 | |
| 30 | ||
| 31 | sislumaonly = sisphbd ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8() | |
| 32 | ||
| 33 | clp = sislumaonly ? input : sisphbd ? input.converttoy() : input.converttoy8() | |
| 34 | ||
| 35 | LOS = string(lowsens) | |
| 36 | HIS = string(highsens/100.0) | |
| 37 | DRK = string(darkstr) | |
| 38 | BRT = string(brightstr) | |
| 39 | MPL = string(msk_pull) | |
| 40 | MPS = string(msk_push) | |
| 41 | ox = clp.width() | |
| 42 | oy = clp.height() | |
| 43 | ||
| 44 | # Parameters that can only be adjusted from within the script | |
| 45 | mbl = 1.58 | |
| 46 | ||
| 47 | sm = clp.bicubicresize(m4_md(ox/rx),m4_md(oy/ry)) | |
| 48 | lg = sm.bicubicresize(ox,oy,1,0) | |
| 49 | chl = VersionNumber() < 2.6 ? mt_lutxy(clp.srmdhae(sre,1),clp.srmdhai(sri,1),"x y -","x y -","x y -") : mt_lutxy(clp.srmdhae(sre,1),clp.srmdhai(sri,1),"x y -", use_expr=3) | |
| 50 | lhl = VersionNumber() < 2.6 ? mt_lutxy(lg.srmdhae(sre,1),lg.srmdhai(sri,1),"x y -","x y -","x y -") : mt_lutxy(lg.srmdhae(sre,1),lg.srmdhai(sri,1),"x y -", use_expr=3) | |
| 51 | mask_i = VersionNumber() < 2.6 ? mt_lutxy(lhl,chl,"y x - y 0.001 + / 255 * "+LOS+" - y 256 + 512 / "+HIS+" + *" ) | |
| 52 | \ : mt_lutxy(lhl,chl,"y x - y 0.001 + / range_max * "+LOS+" scalef - y range_size + 512 scalef / "+HIS+" + *", scale_inputs="floatf", use_expr=1 ) | |
| 53 | ||
| 54 | mask_f = VersionNumber() < 2.6 ? mt_lutxy(sm.mt_expand,sm.mt_inpand,"x y - 4 *") : mt_lutxy(sm.mt_expand,sm.mt_inpand,"x y - 4 *",clamp_float=true,use_expr=1) | |
| 55 | mask_f = VersionNumber() < 2.6 ? mask_f.blur(mbl).bicubicresize(ox,oy,1.0,0).mt_lut(yExpr="255 255 "+MPL+" - 255 "+MPS+" - - / x "+MPL+" - *") | |
| 56 | - | \ : mask_f.blur(mbl).bicubicresize(ox,oy,1.0,0).mt_lut(yExpr="range_max range_max "+MPL+" scalef - range_max "+MPS+" scalef - - / x "+MPL+" scalef - *", scale_inputs="floatf", use_expr=3) |
| 56 | + | \ : mask_f.blur(mbl).bicubicresize(ox,oy,1.0,0).mt_lut(yExpr="range_max range_max "+MPL+" scalef - range_max "+MPS+" scalef - - / x "+MPL+" scalef - *", scale_inputs="floatf", use_expr=2) |
| 57 | ||
| 58 | mmg = mt_merge(lg,clp,mask_i) | |
| 59 | ssc = (ss==1.0) ? clp.repair(mmg,1,0) | |
| 60 | \ : clp.spline64resize(m4_md(ox*ss),m4_md(oy*ss)) | |
| 61 | \ .mt_logic(mmg.mt_expand().bicubicresize(m4_md(ox*ss),m4_md(oy*ss)),"min",U=2,V=2) | |
| 62 | \ .mt_logic(mmg.mt_inpand().bicubicresize(m4_md(ox*ss),m4_md(oy*ss)),"max",U=2,V=2) | |
| 63 | \ .spline64resize(ox,oy) | |
| 64 | umfc = VersionNumber() < 2.6 ? mt_lutxy(clp,ssc,"x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",U=2,V=2) | |
| 65 | \ : mt_lutxy(clp,ssc,"x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",clamp_float=true,use_expr=1,U=2,V=2) | |
| 66 | mfc = mt_merge(clp,umfc,mask_f,U=2,V=2) | |
| 67 | ||
| 68 | bb = cs ? mfc.removegrain(11) : nop() | |
| 69 | xD = cs ? mt_makediff(bb,bb.repair(bb.repair(bb.medianblur(2,-333,-333),1),1)) : nop() | |
| 70 | - | 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=3) : xD
|
| 70 | + | 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
|
| 71 | xDD = cs ? VersionNumber() < 2.6 ? mt_lutxy(xD,mt_makediff(clp,mfc),"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?") | |
| 72 | \ : mt_lutxy(xD,mt_makediff(clp,mfc),"x range_half - y range_half - * 0 < range_half x range_half - abs y range_half - abs < x y ? ?", use_expr=1) : nop() | |
| 73 | mfc = cs ? mfc.mt_adddiff(xDD,U=2,V=2) : mfc | |
| 74 | ||
| 75 | mfc = sislumaonly ? mfc : sisphbd ? CombinePlanes(mfc,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),mfc) | |
| 76 | ||
| 77 | return(show_msk ? mask_f : mfc) | |
| 78 | } | |
| 79 | ||
| 80 | function m4_md(float x) {
| |
| 81 | nx=VersionNumber() < 2.6 ? x<16?16:int(round(x/4.0)*4) : round(x) | |
| 82 | return(nx) | |
| 83 | } | |
| 84 | ||
| 85 | Function srmdhae(clip i, int dr_rad, int count) | |
| 86 | {
| |
| 87 | return count > dr_rad ? i : srmdhae(i.mt_expand(), dr_rad, count+1) | |
| 88 | } | |
| 89 | ||
| 90 | Function srmdhai(clip i, int dr_rad, int count) | |
| 91 | {
| |
| 92 | return count > dr_rad ? i : srmdhai(i.mt_inpand(), dr_rad, count+1) | |
| 93 | } |