Log in

View Full Version : An avisynth function for whitebalancing


HighInBC
20th June 2005, 22:50
This is the pure avisynth version of my earlier perl routine:


function WhiteBalance(clip clip, int r, int g, int b, float bright, float level)
{
largest = ((r > g) ? (r) : (g))
largest = ((largest > b) ? (largest) : (b))
largest = largest * bright
new_r = gradient(1,(largest / Float(r)),level)
new_g = gradient(1,(largest / Float(g)),level)
new_b = gradient(1,(largest / Float(b)),level)
return clip.RGBAdjust(new_r,new_g,new_b,1)

function gradient(float low, float high, float point)
{
return ((high - low) * point) + low
}
}


This function will white balance your image simply by telling it what color an object that should be white is.

I have added the 'level' paramater. here is a break down of the paramaters:

clip: the clip to be effected
r,g,b: the int values of the RGB channels of a pixel that should be white
bright: a brightness modifier, below 1 reduces, above 1 increases, 1 no effect.
level: how much effect, 0 no effect, 1 full effect, enter something like .7-.9 if the function over washes the image.

You will want to set rgb first, then fiddle with level and bright to get what you want.