I have a film that suffers from light leakage, so there is a large spot on the side that is brighter than the rest of the frame. This bright area is consistent throughout the entire film. I can fix this sort of thing in Photoshop for a still image, using a gradient mask corresponding to the light area to be corrected, and correct using a darkening layer.
How can I do a similar thing using AVISynth? I can create a gradient mask, in either black on white, or white on black. Can I use some function in AVISynth to darken this area, blend, or what do you suggest?
+ Reply to Thread
Results 1 to 14 of 14
Oe way to do it would be to use overlay() using the gradient mask; white areas are "transparent" . You might not need to use blend modes depending on the defect, but you can experiment with them
To darken the area, you can use levels() or smoothlevels() and adjust the gamma . Levels takes the same arguments as photoshop levels
So you would have 2 clips , the original with defect, the mask, and a dark version of the video . The white areas of the mask delineate where the dark version "pokes through" to cover up the original video
You could do the same thing with masktools and mt_merge as well
Use an alpha mask and a black frame with the Logo filter.
I ended up using the overlay function of AVISynth and it worked great, but I could not find much logic to the modes like add, blend, darken, etc. I ended up using softlight, which gave a nice blended result. Thanks for the help!
Last edited by kinglerch; 9th Apr 2012 at 07:58.
I have a similar problem on a new film. In this case, the left side of the film is brighter than the right side.
So I created a gradient BMP in photoshop and then used the Overlay function in AVISynth. The result was what I wanted (darkening on the left) the problem is that the result had very wide banding, which was weird because the gradient from photoshop seemed very clean to me. Am I running into a problem with the Overlay function, unable to see all the levels of grey? Or is there another way to do what I am trying to do? Maybe another tool would do a better job with the many levels of grey?
Post your script. Some sample images too. I seem to recall Overlay() does have some problems. Are you working in RGB or YUV? You could also try using mt_merge() from MaskTools.
Last edited by jagabo; 9th Apr 2012 at 08:13.
My source is here, should be YUV
one = AVISource("e:\input.avi")
two = ImageSource("black.bmp")
mask1 = ImageSource("black2.bmp")
overlay(one, two, x=0, y=0, mode="darken", mask=mask1, opacity=.5)
black.bmp is a totally black 1920x1080 square. black2.bmp is my gradient:
"Banding" is "normal" in legal range 8-bit YUV ; White to black is expressed from 16-235 so there are fewer "slots" for expression from a white to black gradient . In full range YUV, values range from 0-255 just like RGB
Your bmp is RGB, but your video source is probably legal range YUV (16-235)
Either convert the RGB bmp to YUV using ConvertToYV12(matrix="PC.709"), or maybe you fiddle with "pc_range=true" for Overlay (internally, I think overlay works in YUY2), but you may have to adjust your gradient
Even in full range RGB and YUV banding is normal. 8 bit color simply isn't enough to eliminate banding in smooth gradients. Using AddGrain() to add noise to the gradient will help.
Is there a function to create a fullrange gradient, similar to maybe mt_edge so I don't have to deal with a bitmap at all? Just something to make a gradual brightness reduction, from left to right?
To verify the problems isn't limited to Overlay() I did a similar adjustment with mt_merge() (and the above images):
grad=ImageSource("grad.bmp").ConvertToYV12(matrix="PC.601") src=ImageSource("flat.png").ConvertToYV12() dark=ColorYUV(src, gain_y=-113, cont_u=-113, cont_v=-113) mt_merge(src, dark, grad, true)
Using full range won't necessarily help because you're probably going back to limited range YUV. Full range only helps if you keep full range all the way. (i.e when viewing, the YUV => back to RGB conversion is done with full range as well)
As jagabo mentioned, you can improve 8-bit banding by dithering it, just add gradfun3() from the dither package
Dithering is just a form of fine noise, but it's a lot more pleasant than adding coarse noise. gradfun3() uses ordered dithering, which is less bitrate intensive to encode
I took jagabo's "yuv.avs" example and used .
You can also work in "fake" 16-bit with avisynth, then dither back to 8-bit, there are several ways to do this, but I find the benefits are minimal. The main problem is 8-bit "legal" range video
You can compare the screenshots attached