Advertisement
Guest User

DeHaloHmod

a guest
May 9th, 2016
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # DeHaloHmod 9 5 2016 http://forum.doom9.org/showthread.php?p=1675762#post1675762
  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")
  71. {
  72.  smooth     = Default(smooth, false)
  73.  strong     = Default(strong, true)
  74.  Maska      = Default(Maska, false)
  75.  analog     = Default(analog, false)
  76.  dirty      = Default(dirty, false)
  77.  DR_Radius  = Default(Radius, dirty ? 6 : smooth ? 4 : 2)
  78.  DR_Str     = Default(Str, smooth ? 5 : 3)
  79.  mode       = Default(mode, 3)
  80.  threshold  = Default(thr, smooth ? 2250 : 140)
  81.  
  82.  hfl = defined(exdehalo) ? eval("input." + exdehalo) : smooth ? input.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) : input.TBilateral(DR_Str,5,0.9,0.9,5,5,0.7,chroma=false)
  83.  
  84.  cm  = dirty ? hfl : input
  85.  
  86.  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)
  87.  
  88.  RM2 = DR_Radius_dhh(EM1.mt_inflate(),DR_Radius,0).mt_inflate()
  89.  
  90.  DeRinging = mt_Merge(hfl, input, smooth ? EM1.mt_inflate(155,155) : EM1)
  91.  DeRinging = Maska ?  DeRinging.Invert() : DeRinging
  92.  
  93. return mt_Merge(input, DeRinging, RM2, u=2, v=2)
  94. }
  95.  
  96. Function DeHaloH(clip input, int "DR_Radius", int "DR_Str", bool "Maska", bool "strong", int "mode", int "threshold")
  97. {
  98.  strong     = Default(strong, true)
  99.  Maska      = Default(Maska, false)
  100.  DR_Radius  = Default(DR_Radius, 2)
  101.  DR_Str     = Default(DR_Str, 15)
  102.  mode       = Default(mode, 0)
  103.  threshold  = Default(threshold, 140)
  104.  
  105.  EM = mode == 0 ? (strong ? input.Camembert_dhh() : input.Camembert_dhhMod()) : EMask_dhh(input, mode, threshold)
  106.  
  107.  RM=DR_Radius_dhh(EM,DR_Radius,0)
  108.  DeRinging  = input.Deen("a2d", 2, DR_Str  , 0, 0, 0, 0, 0)
  109.  DeRinging = Maska ?  DeRinging.Invert() : DeRinging
  110. return mt_Merge(input, DeRinging, RM)
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement