HighInBC
21st June 2005, 18:03
I have made a small applet, it loads a frame and then lets you modify it for white balancing, when you have the desired effect it gives you avisynth code to match the effect.
http://adserton.crackerjack.net/~rambler/screenshot.jpg
To use this you create an image of a frame, and load it in. Then you click on something that should be white with the left mouse button. You can change the level and brightness with the 2 sliders.
You will need:
Activestate perl (free)
the TK module (free)
and the image magick module 'perlmagick' (also free).
I know, what a hassle to install all this stuff.. but if I wrote this into a compilable language it would take forever! For those who know and love perl this should be sraight forward. If you work in compilable languages, then this should be fairly straight forward to create.
Feal free to ask for help getting this running:
use strict;
use Tk;
use Tk::event;
use Image::Magick;
my $frame_image = 'test.bmp';
my $img_master = Image::Magick->new;
$img_master->Read ($frame_image);
$img_master->Write ('temp.bmp');
my($mouse_x,$mouse_y) = (0,0);
my($r_col,$g_col,$b_col) = (1,1,1);
my($bright,$level) = (1,1);
my($avs_line);
my ($lst_clk_x,$lst_clk_y);
my ($res_x,$res_y) = (720,544);
my $image_aspect_ratio = $res_x/$res_y;
my($tk_photo,$curve);
my $main = new MainWindow();
my $input_frame = $main->Frame()->pack();
$input_frame->Label (-text => 'X:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$mouse_x)->pack(-side => 'left');
$input_frame->Label (-text => 'Y:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$mouse_y)->pack(-side => 'left');
$input_frame->Label (-text => 'R:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$r_col)->pack(-side => 'left');
$input_frame->Label (-text => 'G:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$g_col)->pack(-side => 'left');
$input_frame->Label (-text => 'B:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$b_col)->pack(-side => 'left');
$input_frame->Label (-text => 'Bright:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$bright)->pack(-side => 'left');
$input_frame->Label (-text => 'Level:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$level)->pack(-side => 'left');
$input_frame->Label (-text => 'AVS:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$avs_line)->pack(-side => 'left');
$input_frame->Button (
-text => 'Get Frame',
-command => \&load_image
)->pack(-side => 'left');
$input_frame->Button (
-text => 'Clipboard',
-command => [\&clipboard]
)->pack(-side => 'left');
$main->Scale (
-label => 'Bright',
-digits => 4,
-from => 0,
-to => 1.5,
-resolution => .005,
-length => 480,
-variable => \$bright,
-command => \&redo_image
)->pack(-side => 'right');
$main->Scale (
-label => 'level',
-digits => 4,
-from => 0,
-to => 1,
-resolution => .005,
-length => 480,
-variable => \$level,
-command => \&redo_image
)->pack(-side => 'right');
my $canvas = $main ->Canvas();
$canvas->pack (-expand => 1, -fill => 'both');
MainLoop;
warn("Program finished\n");exit;
#______________________________________________________________________________________#
sub clipboard
{
use Win32::Clipboard;
my $CLIP = Win32::Clipboard();
$CLIP ->Set($avs_line);
return;
}
sub redo_image
{
my($r,$g,$b) = wb($r_col,$g_col,$b_col,$bright,$level);
$avs_line = "RGBAdjust($r,$b,$g)";
my $img = $img_master->Clone();
$img->Evaluate (value => $r, operator => 'Multiply', channel => 'red');
$img->Evaluate (value => $g, operator => 'Multiply', channel => 'green');
$img->Evaluate (value => $b, operator => 'Multiply', channel => 'blue');
$img->Write ('temp.bmp');
&load_image
}
sub mouse_pos
{
($mouse_x, $mouse_y) = ($Tk::event->x, $Tk::event->y);
}
sub mouse_click1
{
($lst_clk_x,$lst_clk_y) = ($Tk::event->x, $Tk::event->y);
my @stuff = $img_master->GetPixels
(
x => $mouse_x,
y => $mouse_y,
width => 1,
height => 1,
map =>'RGB'
);
$r_col = int($stuff[0] * 255);
$g_col = int($stuff[1] * 255);
$b_col = int($stuff[2] * 255);
&redo_image();
}
sub wb
{
my $r = shift;
my $g = shift;
my $b = shift;
my $modify = shift || 1;
my $level = shift || 1;
my $largest = $r;
($largest = $g) if ($g > $largest);
($largest = $b) if ($b > $largest);
$largest = ($largest * $modify);
$r = gradient(1,($largest/$r),$level);
$g = gradient(1,($largest/$g),$level);
$b = gradient(1,($largest/$b),$level);
return ($r,$g,$b);
sub gradient
{
my($low,$high,$point) = @_;
return (($high - $low) * $point) + $low;
}
}
sub load_image
{
$tk_photo = $canvas->Photo
(
-file => 'temp.bmp'
);
$canvas->configure (
-width => $tk_photo->width(),
-height => $tk_photo->height()
);
my $img_id = $canvas->createImage
(0,0,
-anchor => 'nw',
-image => $tk_photo
);
$canvas->bind ('current', '<Motion>', \&mouse_pos);
$canvas->bind ('current', '<Button 1>', \&mouse_click1);
}
http://adserton.crackerjack.net/~rambler/screenshot.jpg
To use this you create an image of a frame, and load it in. Then you click on something that should be white with the left mouse button. You can change the level and brightness with the 2 sliders.
You will need:
Activestate perl (free)
the TK module (free)
and the image magick module 'perlmagick' (also free).
I know, what a hassle to install all this stuff.. but if I wrote this into a compilable language it would take forever! For those who know and love perl this should be sraight forward. If you work in compilable languages, then this should be fairly straight forward to create.
Feal free to ask for help getting this running:
use strict;
use Tk;
use Tk::event;
use Image::Magick;
my $frame_image = 'test.bmp';
my $img_master = Image::Magick->new;
$img_master->Read ($frame_image);
$img_master->Write ('temp.bmp');
my($mouse_x,$mouse_y) = (0,0);
my($r_col,$g_col,$b_col) = (1,1,1);
my($bright,$level) = (1,1);
my($avs_line);
my ($lst_clk_x,$lst_clk_y);
my ($res_x,$res_y) = (720,544);
my $image_aspect_ratio = $res_x/$res_y;
my($tk_photo,$curve);
my $main = new MainWindow();
my $input_frame = $main->Frame()->pack();
$input_frame->Label (-text => 'X:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$mouse_x)->pack(-side => 'left');
$input_frame->Label (-text => 'Y:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$mouse_y)->pack(-side => 'left');
$input_frame->Label (-text => 'R:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$r_col)->pack(-side => 'left');
$input_frame->Label (-text => 'G:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$g_col)->pack(-side => 'left');
$input_frame->Label (-text => 'B:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$b_col)->pack(-side => 'left');
$input_frame->Label (-text => 'Bright:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$bright)->pack(-side => 'left');
$input_frame->Label (-text => 'Level:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$level)->pack(-side => 'left');
$input_frame->Label (-text => 'AVS:')->pack(-side => 'left');
$input_frame->Label (-textvariable => \$avs_line)->pack(-side => 'left');
$input_frame->Button (
-text => 'Get Frame',
-command => \&load_image
)->pack(-side => 'left');
$input_frame->Button (
-text => 'Clipboard',
-command => [\&clipboard]
)->pack(-side => 'left');
$main->Scale (
-label => 'Bright',
-digits => 4,
-from => 0,
-to => 1.5,
-resolution => .005,
-length => 480,
-variable => \$bright,
-command => \&redo_image
)->pack(-side => 'right');
$main->Scale (
-label => 'level',
-digits => 4,
-from => 0,
-to => 1,
-resolution => .005,
-length => 480,
-variable => \$level,
-command => \&redo_image
)->pack(-side => 'right');
my $canvas = $main ->Canvas();
$canvas->pack (-expand => 1, -fill => 'both');
MainLoop;
warn("Program finished\n");exit;
#______________________________________________________________________________________#
sub clipboard
{
use Win32::Clipboard;
my $CLIP = Win32::Clipboard();
$CLIP ->Set($avs_line);
return;
}
sub redo_image
{
my($r,$g,$b) = wb($r_col,$g_col,$b_col,$bright,$level);
$avs_line = "RGBAdjust($r,$b,$g)";
my $img = $img_master->Clone();
$img->Evaluate (value => $r, operator => 'Multiply', channel => 'red');
$img->Evaluate (value => $g, operator => 'Multiply', channel => 'green');
$img->Evaluate (value => $b, operator => 'Multiply', channel => 'blue');
$img->Write ('temp.bmp');
&load_image
}
sub mouse_pos
{
($mouse_x, $mouse_y) = ($Tk::event->x, $Tk::event->y);
}
sub mouse_click1
{
($lst_clk_x,$lst_clk_y) = ($Tk::event->x, $Tk::event->y);
my @stuff = $img_master->GetPixels
(
x => $mouse_x,
y => $mouse_y,
width => 1,
height => 1,
map =>'RGB'
);
$r_col = int($stuff[0] * 255);
$g_col = int($stuff[1] * 255);
$b_col = int($stuff[2] * 255);
&redo_image();
}
sub wb
{
my $r = shift;
my $g = shift;
my $b = shift;
my $modify = shift || 1;
my $level = shift || 1;
my $largest = $r;
($largest = $g) if ($g > $largest);
($largest = $b) if ($b > $largest);
$largest = ($largest * $modify);
$r = gradient(1,($largest/$r),$level);
$g = gradient(1,($largest/$g),$level);
$b = gradient(1,($largest/$b),$level);
return ($r,$g,$b);
sub gradient
{
my($low,$high,$point) = @_;
return (($high - $low) * $point) + $low;
}
}
sub load_image
{
$tk_photo = $canvas->Photo
(
-file => 'temp.bmp'
);
$canvas->configure (
-width => $tk_photo->width(),
-height => $tk_photo->height()
);
my $img_id = $canvas->createImage
(0,0,
-anchor => 'nw',
-image => $tk_photo
);
$canvas->bind ('current', '<Motion>', \&mouse_pos);
$canvas->bind ('current', '<Button 1>', \&mouse_click1);
}