HighInBC
18th June 2005, 22:40
This is a very simple perl subroutine for white balancing clips in avisynth(it produces an RGBAdjust command), it should be very easy to understand:
sub wb
{
use Win32::Clipboard;
$CLIP = Win32::Clipboard();
my $r = shift;
my $g = shift;
my $b = shift;
my $modify = shift || 1;
my $largest = $r;
($largest = $g) if ($g > $largest);
($largest = $b) if ($b > $largest);
$largest = ($largest * $modify);
$r = $largest/$r;
$g = $largest/$g;
$b = $largest/$b;
my $avs_line = "RGBAdjust($r,$g,$b,1)";
$CLIP ->Set($avs_line);
return $avs_line;
}
to use this, you must have ActiveState Perl installed. you use this by taking the RGB values of a pixel from the clip that should be white:
wb(R, G, B);
or
wb(R, G, B, L);
L is for adjusting brightness of final image. below 1 lowers brightness above 1 increases, 1 has no effect.
The program will put an RGBAdjust command into the windows clipboard for you to paste into your script.
Example:
wb(224, 205, 184);
gives:
RGBAdjust(1,1.09268292682927,1.21739130434783,1)
and
wb(224, 205, 184, 0.95)
gives:
RGBAdjust(0.95,1.0380487804878,1.15652173913043,1)
Without using the L value to adjust brightness, you will find oversaturation common, I find a value from .8-1 works well.
I have included before and after images, in this case I gave the sub the color fo a pixel on the table and it gave me:
RGBAdjust(1,1.17058823529412,2.09473684210526,1)
Before:
http://adserton.crackerjack.net/~rambler/before.jpg
After:
http://adserton.crackerjack.net/~rambler/after.jpg
If you are using a version of perl other than ActiveState, the Win32::Clipboard module may not be available, to make the script work on your perl interpreter simply remove the following lines:
use Win32::Clipboard;
$CLIP = Win32::Clipboard();
$CLIP ->Set($avs_line);
The sub's return value will be the avisynth code.
sub wb
{
use Win32::Clipboard;
$CLIP = Win32::Clipboard();
my $r = shift;
my $g = shift;
my $b = shift;
my $modify = shift || 1;
my $largest = $r;
($largest = $g) if ($g > $largest);
($largest = $b) if ($b > $largest);
$largest = ($largest * $modify);
$r = $largest/$r;
$g = $largest/$g;
$b = $largest/$b;
my $avs_line = "RGBAdjust($r,$g,$b,1)";
$CLIP ->Set($avs_line);
return $avs_line;
}
to use this, you must have ActiveState Perl installed. you use this by taking the RGB values of a pixel from the clip that should be white:
wb(R, G, B);
or
wb(R, G, B, L);
L is for adjusting brightness of final image. below 1 lowers brightness above 1 increases, 1 has no effect.
The program will put an RGBAdjust command into the windows clipboard for you to paste into your script.
Example:
wb(224, 205, 184);
gives:
RGBAdjust(1,1.09268292682927,1.21739130434783,1)
and
wb(224, 205, 184, 0.95)
gives:
RGBAdjust(0.95,1.0380487804878,1.15652173913043,1)
Without using the L value to adjust brightness, you will find oversaturation common, I find a value from .8-1 works well.
I have included before and after images, in this case I gave the sub the color fo a pixel on the table and it gave me:
RGBAdjust(1,1.17058823529412,2.09473684210526,1)
Before:
http://adserton.crackerjack.net/~rambler/before.jpg
After:
http://adserton.crackerjack.net/~rambler/after.jpg
If you are using a version of perl other than ActiveState, the Win32::Clipboard module may not be available, to make the script work on your perl interpreter simply remove the following lines:
use Win32::Clipboard;
$CLIP = Win32::Clipboard();
$CLIP ->Set($avs_line);
The sub's return value will be the avisynth code.