Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 2017.03.08 1st release
- # Masked_DHA with high bit support, need masktools 2.2.4 or up in avs26 and avs+
- 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")
- {
- rx = default( rx, 2.0 )
- ry = default( ry, 2.0 )
- darkstr = default( darkstr, 1.0 )
- brightstr = default( brightstr, 1.0 )
- lowsens = default( lowsens, 50 )
- highsens = default( highsens, 50 )
- msk_pull = default( msk_pull, 48 )
- msk_push = default( msk_push, 192 )
- ss = default( ss, 1.5 )
- show_msk = default( show_msk, false )
- cs = default( cs, false )
- sre = default( search_rade, 1 )
- sri = default( search_radi, sre )
- rx = max(rx, 1.0)
- ry = max(ry, 1.0)
- darkstr = max(min(darkstr, 1.0), 0.0)
- lowsens = max(min(lowsens, 100), 0)
- highsens = max(min(highsens, 100), 0)
- msk_pull = max(min(msk_pull, 254), 0)
- msk_push = max(min(msk_push, 255), msk_pull + 1)
- ss = max(ss, 1.0)
- ssispmt = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
- sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8()
- clp = sislumaonly ? input : ssispmt ? input.converttoy() : input.converttoy8()
- LOS = string(lowsens)
- HIS = string(highsens/100.0)
- DRK = string(darkstr)
- BRT = string(brightstr)
- MPL = string(msk_pull)
- MPS = string(msk_push)
- ox = clp.width()
- oy = clp.height()
- # Parameters that can only be adjusted from within the script
- mbl = 1.58
- sm = clp.bicubicresize(m4_md(ox/rx),m4_md(oy/ry))
- lg = sm.bicubicresize(ox,oy,1,0)
- chl = mt_lutxy(clp.srmdhae(sre,1),clp.srmdhai(sri,1),"x y -","x y -","x y -")
- lhl = mt_lutxy(lg.srmdhae(sre,1),lg.srmdhai(sri,1),"x y -","x y -","x y -")
- mask_i = VersionNumber() < 2.6 ? mt_lutxy(lhl,chl,"y x - y 0.001 + / 255 * "+LOS+" - y 256 + 512 / "+HIS+" + *" )
- \ : mt_lutxy(lhl,chl,"clamp_f_i8 y x - y 0.001 + / range_max * "+LOS+" #F - y range_size + 512 #F / "+HIS+" + *" )
- mask_f = VersionNumber() < 2.6 ? mt_lutxy(sm.mt_expand,sm.mt_inpand,"x y - 4 *") : mt_lutxy(sm.mt_expand,sm.mt_inpand,"clamp_f_i8 x y - 4 *")
- 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+" - *")
- \ : mask_f.blur(mbl).bicubicresize(ox,oy,1.0,0).mt_lut(yExpr="clamp_f_i8 range_max range_max "+MPL+" #F - range_max "+MPS+" #F - - / x "+MPL+" #F - *")
- mmg = mt_merge(lg,clp,mask_i)
- ssc = (ss==1.0) ? clp.repair(mmg,1,0)
- \ : clp.spline64resize(m4_md(ox*ss),m4_md(oy*ss))
- \ .mt_logic(mmg.mt_expand().bicubicresize(m4_md(ox*ss),m4_md(oy*ss)),"min",U=2,V=2)
- \ .mt_logic(mmg.mt_inpand().bicubicresize(m4_md(ox*ss),m4_md(oy*ss)),"max",U=2,V=2)
- \ .spline64resize(ox,oy)
- umfc = VersionNumber() < 2.6 ? mt_lutxy(clp,ssc,"x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",U=2,V=2)
- \ : mt_lutxy(clp,ssc,"clamp_f_i8 x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",U=2,V=2)
- mfc = mt_merge(clp,umfc,mask_f,U=2,V=2)
- bb = cs ? mfc.removegrain(11) : nop()
- xD = cs ? mt_makediff(bb,bb.repair(bb.repair(bb.medianblur(2,-333,-333),1),1)) : nop()
- xD = cs ? VersionNumber() < 2.6 ? xD.mt_lut("x 128 - 2.49 * 128 +") : xD.mt_lut("clamp_f_i8 x range_half - 2.49 * range_half +") : xD
- 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 ? ?")
- \ : 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 ? ?") : nop()
- mfc = cs ? mfc.mt_adddiff(xDD,U=2,V=2) : mfc
- mfc = sislumaonly ? mfc : ssispmt ? CombinePlanes(mfc,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),mfc)
- return(show_msk ? mask_f : mfc)
- }
- function m4_md(float x) {
- nx=VersionNumber() < 2.6 ? x<16?16:int(round(x/4.0)*4) : round(x)
- return(nx)
- }
- Function srmdhae(clip i, int dr_rad, int count)
- {
- return count > dr_rad ? i : srmdhae(i.mt_expand(), dr_rad, count+1)
- }
- Function srmdhai(clip i, int dr_rad, int count)
- {
- return count > dr_rad ? i : srmdhai(i.mt_inpand(), dr_rad, count+1)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement