Advertisement
Guest User

DeHalo_alpha_MT2

a guest
Nov 23rd, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # DeHalo_alpha with high bit support, need masktools 2.2.5 or up in avs26 and avs+
  2. # 2017.11.23 added Z4ST1N optimise suggestion
  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. ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
  39.  
  40. sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8()
  41.  
  42. clp = sislumaonly ? input : ssispmt ? 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)  : mt_lutxy(clp  .srdha2e(sre,1),clp  .srdha2i(sri,1),"x y -",U=1,V=1)
  53. ugly   = sre==1 && sri==1 ? halos.mt_edge(mode="min/max", thY1=0, thY2=255) : mt_lutxy(halos.srdha2e(sre,1),halos.srdha2i(sri,1),"x y -",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, "clamp_f_i8 y x - y 0.001 + / range_max * "+LOS+" scalef - y range_size + 512 scalef / "+HIS+" + *" )
  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,"clamp_f_i8 x y < x x y - "+DRK+" * - x x y - "+BRT+" * - ?",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("clamp_f_i8 x range_half - 2.49 * range_half +") : 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 ? ?") : nop()
  70. them = cs ? them.mt_adddiff(xDD,U=2,V=2) : them
  71.  
  72. them   = sislumaonly ? them : ssispmt ? 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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement