Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th June 2005, 23:40   #1  |  Link
HighInBC
Registered User
 
HighInBC's Avatar
 
Join Date: Jan 2003
Location: Victoria, BC, Canada
Posts: 144
I made a perl script that makes an RGBAdjust cmd for white balancing

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:

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:

After:


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.

Last edited by HighInBC; 19th June 2005 at 03:33. Reason: Spelling error
HighInBC is offline   Reply With Quote
Old 19th June 2005, 01:33   #2  |  Link
HighInBC
Registered User
 
HighInBC's Avatar
 
Join Date: Jan 2003
Location: Victoria, BC, Canada
Posts: 144
Oh, for those not familiar at all with perl, once you install it, just make a file called 'whitebalance.pl', or any name, but with a .pl extension.

paste the subroutine in the file and at the top put the wb(R,G,B[,L]); command.

run the script and the answer will be in the clipboard.
HighInBC is offline   Reply With Quote
Old 19th June 2005, 17:16   #3  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,607
hmmm. this should also be achievable using some frameevaluating within AVS.

can you describe the maths behind the perl-script, please?
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 19th June 2005, 17:28   #4  |  Link
HighInBC
Registered User
 
HighInBC's Avatar
 
Join Date: Jan 2003
Location: Victoria, BC, Canada
Posts: 144
sure, you take the largest value of R,G or B then multiply it by the brightness modifier, and call it 'X'.

You then divide each channel by X and then place those results into the RGBAdjust command.

RGBAdjust then multiplies each pixel with those numbers.

if the RGB values you gave it were of a pixel that should have been white, the RGBAdjust values will make it white and adjust everything else accordingly.

I just posted a pure avisynth version of the routine.

Thanks for looking into this.
HighInBC is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:22.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.