Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function BalanceBorders(clip c, int cTop, int cBottom, int cLeft, int cRight, int "thresh", int "blur")
- {
- Assert(is420(c), "This is not an YUV420 clip. Convert color space to YV12 before using BalanceBorders().")
- t = Int(Pow(2, (BitsPerComponent(c)-1)))
- thresh = Default(thresh, t)
- blur = Default(blur, 999)
- Assert(blur > 0, "Blur parameter in BalanceBorders() must be > 0")
- Assert(thresh > 0, "Thresh parameter in BalanceBorders() must be > 0")
- c
- cTop >0 ? BalanceTopBorder(cTop, thresh, blur).TurnRight() : last.TurnRight()
- cLeft >0 ? BalanceTopBorder(cLeft, thresh, blur).TurnRight() : last.TurnRight()
- cBottom >0 ? BalanceTopBorder(cBottom, thresh, blur).TurnRight() : last.TurnRight()
- cRight >0 ? BalanceTopBorder(cRight, thresh, blur).TurnRight() : last.TurnRight()
- }
- function BalanceTopBorder(clip c, int cTop, int "thresh", int "blur")
- {
- cWidth = c.width
- cHeight = c.height
- cTop = min(cTop,cHeight-1)
- blurWidth = max(4,floor(cWidth/blur))
- c2 = c.PointResizeMT(cWidth*2,cHeight*2)
- c2.\
- Crop(0,cTop*2,cWidth*2,2)
- PointResizeMT(cWidth*2,cTop*2)
- BilinearResizeMT(blurWidth*2,cTop*2)
- Blur(1.5,0.1)
- BilinearResizeMT(cWidth*2,cTop*2)
- referenceBlur = last
- original = c2.Crop(0,0,cWidth*2,cTop*2)
- original
- BilinearResizeMT(blurWidth*2,cTop*2)
- Blur(1.5,0.1)
- BilinearResizeMT(cWidth*2,cTop*2)
- originalBlur = last
- balanced = mt_lutXYZ(original,originalBlur,referenceBlur,"z y - x +",y=3,u=3,v=3)
- difference = mt_makeDiff(balanced,original,y=3,u=3,v=3)
- t = Pow(2, (BitsPerComponent(c)-1))
- tp = string(t+thresh)
- tm = string(t-thresh)
- difference = difference.mt_lut("x "+tp+" > "+tp+" x ?",y=3,u=3,v=3)
- difference = difference.mt_lut("x "+tm+" < "+tm+" x ?",y=3,u=3,v=3)
- mt_addDiff(original,difference,y=3,u=3,v=3)
- StackVertical(last,c2.Crop(0,cTop*2,cWidth*2,(cHeight-cTop)*2)).PointResizeMT(cWidth,cHeight)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement