Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # FixChromaBleedingMod v1.3
- Function FixChromaBleedingMod (clip input, int "cxShift", int "cyShift", float "thr", float "strength", bool "f", float "opacity", bool "n", bool "xysh", bool "Bic") {
- xShift = default ( cxShift, -4 )
- yShift = default ( cyShift, -4 )
- thr = default ( thr, 4.0 )
- stre = default ( strength, 0.8 )
- f = default ( f, true )
- n = default ( n, false )
- sh = default ( xysh, false )
- Bic = default ( Bic, false )
- opacity = default ( opacity, 1 )
- # prepare to work on the V channel and reduce to speed up and filter noise
- areaf = input.tweak(sat=thr).VtoY.ReduceBy2
- area = n ? input.tweak(sat=thr).VtoY.Blur(1) : input.tweak(sat=thr).VtoY
- # select and normalize both extremes of the scale
- red = f ? areaf.Levels(255,1.0,255,255,0) : area.Levels(255,1.0,255,255,0)
- blue = f ? areaf.Levels(0,1.0,0,0,255) : area.Levels(0,1.0,0,0,255)
- # merge both masks
- maskc = n ? MergeLuma(red, blue, 0.5).Levels(250,1.0,250,255,0) : f ? MergeLuma(red, blue, 0.5).Levels(250,1.0,250,255,0) : MergeLuma(red, blue, 0.5).Blur(1).Levels(250,1.0,250,255,0)
- # expand to cover beyond the bleeding areas and shift to compensate the resizing
- maskc = IsPlanar(input) ? maskc.mt_edge("0 0 0 1 0 0 0 0 0", 0,255,0,255).mt_edge("1 1 1 1 1 1 0 0 0", 0,255,0,255) : maskc.ConvertToRGB32.GeneralConvolution(0,"0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0").ConvertToYV12
- # back to full size and binarize (also a trick to expand)
- maskc = Bic ? maskc.BicubicResize(Width(input),Height(input)).Levels(10,1.0,10,0,255) : maskc.BilinearResize(Width(input),Height(input)).Levels(10,1.0,10,0,255)
- # prepare a version of the image that has its chroma shifted and less saturated
- input_c = sh ? input.ChromaShiftSP(x=xShift,y=yShift).tweak(sat=stre) : input.ChromaShift(C=xShift).tweak(sat=stre)
- # combine both images using the mask
- return input.overlay(input_c,mask=maskc,mode="blend",opacity=opacity)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement