Guest User

DeHaloHmod

a guest
Jun 22nd, 2016
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # DeHaloHmod 22 6 2016
  2.  
  3. function GreyCenteredToMask_dhh(clip input) {
  4. input.Levels(128, 1, 255, 0, 255, false)
  5. one = last
  6. input.Levels(0, 1, 128, 255, 0, false)
  7. two = last
  8. Overlay(one, two, mode="lighten")
  9. }
  10.  
  11.  
  12. function FastLineDarkenMOD3_dhh( clip c, int "strength", int "prot", int "luma_cap", int "threshold", int "thinning")
  13. {
  14. ## parameters ##
  15. str        = string(default(strength, 48) /128.)
  16. lum        = string(default(luma_cap, 191))
  17. protection = default(prot,5)
  18. thr        = string(default(threshold, 4))
  19. thinning   = default(thinning,0)
  20. thn        = string(thinning /16.)
  21.  
  22. ## filtering ##
  23. exin    = c.mt_expand(thy=255/(protection+1)).mt_inpand()
  24. diff    = mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x",u=2, v=2)
  25. 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.
  26. thick   = mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x",u=2, v=2)
  27. thin    = mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2)
  28.  
  29. return (thinning == 0) ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2)
  30. }
  31.  
  32.  
  33. function Camembert_dhh(clip input) {
  34.  
  35. input
  36. SmoothUV(3,200,false)
  37. Overlay(last, Blur(1).Blur(1), mode="difference")
  38. GreyCenteredToMask_dhh().greyscale()
  39. Levels(0, 1, 115, 0, 255, false)
  40. mask1 = last
  41. Blur(1)
  42. Levels(0, 0.4, 64, 0, 255, false)
  43. mask = last
  44. Blur(1).Blur(1)
  45. Levels(0, 1, 30, 0, 255, false).Blur(1)
  46. mask2 = last
  47. return (mask2)
  48. }
  49.  
  50. function Camembert_dhhMod(clip input)
  51. {
  52.  EM1=input.Camembert_dhh()
  53.  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()
  54.  return mt_logic(EM1, EM2, "and")
  55. }
  56.  
  57. Function EMask_dhh(clip i, int mode, int trh)
  58. {
  59. e_mask = mode == 1 ? mt_makediff(i.blur(1.58).blur(1.58),i).mt_binarize(threshold=trh).mt_inflate().mt_inflate() :
  60.      \   mode == 2 ? mt_logic(i.mt_binarize(105,upper=true).mt_expand(),i.mt_binarize(110,upper=false).mt_expand(),"and").mt_deflate() :
  61.      \   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()
  62. return e_mask
  63. }
  64.  
  65. Function DR_Radius_dhh(clip i, int dr_rad, int count)
  66. {
  67. return count > dr_rad ? i : DR_Radius_dhh(i.mt_expand(), dr_rad, count+1)
  68. }
  69.  
  70. Function DeHaloHmod(clip input, int "Radius", int "Str", bool "Maska", bool "strong", int "mode", int "thr", string "exdehalo", bool "analog", bool "dirty", bool "smooth", bool "anime", bool "pel2", bool "usedeen", bool "maskpel2")
  71. {
  72.  usedeen    = Default(usedeen, false)
  73.  smooth     = Default(smooth, false)
  74.  strong     = Default(strong, true)
  75.  Maska      = Default(Maska, false)
  76.  analog     = Default(analog, false)
  77.  dirty      = Default(dirty, false)
  78.  DR_Radius  = Default(Radius, dirty ? 6 : smooth ? 4 : 2)
  79.  DR_Str     = Default(Str, smooth ? 5 : usedeen ? 15 : 3)
  80.  mode       = Default(mode, usedeen ? 0 : 3)
  81.  threshold  = Default(thr, smooth ? 2250 : 140)
  82.  anime      = Default(anime, usedeen ? false : true)
  83.  pel2       = Default(pel2, false)
  84.  maskpel2   = Default(maskpel2, false)
  85.  
  86.  oclip = pel2 ? input.nnedi3_rpow2(rfactor=2) : input
  87.  hfl = defined(exdehalo) ? eval("oclip." + exdehalo) : smooth ? oclip.DeHalo_alpha_mt(darkstr=0.2,brightstr=0.8).yahr2(dirty ? 8 : 16).TBilateral(DR_Str,5,0.9,0.9,5,5,0.7,chroma=false) : usedeen ? oclip.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0) : oclip.TBilateral(DR_Str,5,0.9,0.9,5,5,0.7,chroma=false)
  88.  hfl = pel2 && !(maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
  89.  
  90.  cm  = dirty ? hfl : input
  91.  
  92.  cm  = !(dirty && pel2) && maskpel2 ? cm.nnedi3_rpow2(rfactor=2) : cm
  93.  
  94.  EM1 = mode == 0 ? (strong ? Camembert_dhh(analog ? cm.ColorYUV(autogain=true) : cm) : Camembert_dhhMod(analog ? cm.ColorYUV(autogain=true) : cm)) : EMask_dhh(analog ? cm.ColorYUV(autogain=true) : cm, mode, threshold)
  95.  
  96.  EM1 = maskpel2 ? EM1.PointResize(input.Width(),input.Height()) : EM1
  97.  
  98.  hfl = pel2 && (maskpel2 && dirty) ? hfl.PointResize(input.Width(),input.Height()) : hfl
  99.  
  100.  RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate()
  101.  
  102.  DeRinging = anime ? mt_Merge(hfl, input, smooth ? EM1.mt_inflate(155,155) : EM1) : hfl
  103.  DeRinging = Maska ?  DeRinging.Invert() : DeRinging
  104.  
  105. return mt_Merge(input, DeRinging, RM2, u=2, v=2)
  106. }
  107.  
  108. Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold")
  109. {
  110.  strong     = Default(strong, true)
  111.  Maska      = Default(Maska, false)
  112.  DR_Radius  = Default(DR_Radius, 2)
  113.  DR_Str     = Default(DR_Str, 15)
  114.  mode       = Default(mode, 0)
  115.  threshold  = Default(threshold, 140)
  116.  
  117.  EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
  118.  
  119.  RM=DR_Radius_dhh(EM,DR_Radius,0)
  120.  DeRinging  = input.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0)
  121.  DeRinging = Maska ?  DeRinging.Invert() : DeRinging
  122. return mt_Merge(input, DeRinging, RM)
  123. }
RAW Paste Data