Advertisement
Guest User

bb

a guest
Jul 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. function BalanceBorders(clip c, int cTop, int cBottom, int cLeft, int cRight, int "thresh", int "blur")
  2. {
  3. Assert(is420(c), "This is not an YUV420 clip. Convert color space to YV12 before using BalanceBorders().")
  4.  
  5. t = Int(Pow(2, (BitsPerComponent(c)-1)))
  6. thresh = Default(thresh, t)
  7. blur = Default(blur, 999)
  8.  
  9. Assert(blur > 0, "Blur parameter in BalanceBorders() must be > 0")
  10. Assert(thresh > 0, "Thresh parameter in BalanceBorders() must be > 0")
  11.  
  12. c
  13. cTop >0 ? BalanceTopBorder(cTop, thresh, blur).TurnRight() : last.TurnRight()
  14. cLeft >0 ? BalanceTopBorder(cLeft, thresh, blur).TurnRight() : last.TurnRight()
  15. cBottom >0 ? BalanceTopBorder(cBottom, thresh, blur).TurnRight() : last.TurnRight()
  16. cRight >0 ? BalanceTopBorder(cRight, thresh, blur).TurnRight() : last.TurnRight()
  17. }
  18.  
  19. function BalanceTopBorder(clip c, int cTop, int "thresh", int "blur")
  20. {
  21. cWidth = c.width
  22. cHeight = c.height
  23. cTop = min(cTop,cHeight-1)
  24. blurWidth = max(4,floor(cWidth/blur))
  25.  
  26. c2 = c.PointResizeMT(cWidth*2,cHeight*2)
  27.  
  28. c2.\
  29. Crop(0,cTop*2,cWidth*2,2)
  30. PointResizeMT(cWidth*2,cTop*2)
  31. BilinearResizeMT(blurWidth*2,cTop*2)
  32. Blur(1.5,0.1)
  33. BilinearResizeMT(cWidth*2,cTop*2)
  34. referenceBlur = last
  35.  
  36. original = c2.Crop(0,0,cWidth*2,cTop*2)
  37.  
  38. original
  39. BilinearResizeMT(blurWidth*2,cTop*2)
  40. Blur(1.5,0.1)
  41. BilinearResizeMT(cWidth*2,cTop*2)
  42. originalBlur = last
  43.  
  44. balanced = mt_lutXYZ(original,originalBlur,referenceBlur,"z y - x +",y=3,u=3,v=3)
  45. difference = mt_makeDiff(balanced,original,y=3,u=3,v=3)
  46.  
  47. t = Pow(2, (BitsPerComponent(c)-1))
  48. tp = string(t+thresh)
  49. tm = string(t-thresh)
  50. difference = difference.mt_lut("x "+tp+" > "+tp+" x ?",y=3,u=3,v=3)
  51. difference = difference.mt_lut("x "+tm+" < "+tm+" x ?",y=3,u=3,v=3)
  52.  
  53. mt_addDiff(original,difference,y=3,u=3,v=3)
  54.  
  55. StackVertical(last,c2.Crop(0,cTop*2,cWidth*2,(cHeight-cTop)*2)).PointResizeMT(cWidth,cHeight)
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement