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 Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 23rd January 2006, 02:55   #1  |  Link
SomeJoe
Registered User
 
Join Date: Jan 2003
Posts: 315
New Filter: WhiteBalance

My first attempt at writing an AVISynth filter, so I hope I did it right.

This filter can correct the white balance of video that was filmed with a camera where the white balance was incorrectly set or didn't have an adjustment. Especially useful for home video filmed indoors on consumer camcorders, or filmed outdoors under overcast skies.

Has some features that result in more accurate white balance adjustment that attempting to use RGBAdjust() or ColorYUV().

Available here. Documentation included in the .zip archive.

Please post any comments, good, bad, and ugly.
__________________
- SomeJoe
SomeJoe is offline   Reply With Quote
Old 23rd January 2006, 14:54   #2  |  Link
communist
Registered User
 
Join Date: Jul 2003
Posts: 1,152
Thank you for your filter
Either I'm using it wrong or it is very picky / accurate about which values to turn to white or not. The following is a construction model and it was completely white. Using ColorYUV(autowhite=true) it is just as it should be:


Script

AviSource("wb_sample.avi")
WhiteBalance(r1=147, g1=180, b1=244)


Tweaking the value I can get that green smear away but then I either end up having a blue or red tint.

Would it be possible to add an option to input an (rectangular) area (from one frame) with near white / black pixels that are then averaged - so one can specify a block as a sample and the filter will work with the values obtained from there to calculate the Whitebalance?

Last edited by communist; 23rd January 2006 at 14:57.
communist is offline   Reply With Quote
Old 23rd January 2006, 16:14   #3  |  Link
SomeJoe
Registered User
 
Join Date: Jan 2003
Posts: 315
Hi communist, thanks for trying the filter.

I think definitely on this footage that you're going to need to specify two points with maximum brightness separation for the filter to work as intended. I took your source and came up with the following:

The lightest area of a neutral object appears to be an interior wall of the model, with RGB=144/182/245.

The darkest area of a neutral object appears to be in the shadow of the model on the table surface (extreme left side of the picture), with RGB=77/115/152.

Try:

Code:
WhiteBalance(r1=144,g1=182,b1=245,r2=77,g2=115,b2=152)
On your other question, I'm wary of trying to do some type of automatic selection of values, similar to ColorYUV's "autowhite=true". Obviously, (especially on footage like your source), it's difficult to program the logic necessary for the filter to accurately determine what object/surface is supposed to be white. It's not necessarily the object with the highest luminance.
__________________
- SomeJoe
SomeJoe is offline   Reply With Quote
Old 23rd January 2006, 16:48   #4  |  Link
hanfrunz
Registered User
 
hanfrunz's Avatar
 
Join Date: Feb 2002
Location: Germany
Posts: 540
@SomeJoe:

nice filter! You could add a simple GUI (Look here) with a color picker. Will you publish the sourcecode?

regards,
hanfrunz
hanfrunz is offline   Reply With Quote
Old 24th January 2006, 15:17   #5  |  Link
SomeJoe
Registered User
 
Join Date: Jan 2003
Posts: 315
Hi hanfrunz,

Thanks for the link. A GUI might be very nice for this filter. Unfortunately, my programming roots are "old school" (8-bit assembly for microcontrollers and Pascal), so object-oriented C++ is a bit new to me. It may take me some time to figure out.

I've uploaded a new .zip file which includes the source. It's quite straightforward -- the structure is lifted straight from SimpleSample. I commented it reasonably well, but there are a few places that could use more comments.
__________________
- SomeJoe
SomeJoe is offline   Reply With Quote
Old 25th January 2006, 12:40   #6  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Since you haven't published the source, I cannot comment on your algorithms.

"autowhite" is very simple. It makes sure that the average u/v is 128 (grey). This is far too simple for proper white balance correction. But my experiments on RAW photo development has given me some insights into WB. Unfortunately all of it is in RGB-space, so I don't know exactly how it translates into YUV.

However, proper white balance has to be done on linear space data, that means that the sRGB gamma correction has to be "undone". Basicly this gives an algorithm of:

apply gamma(0.45) -> WB correction -> apply gamma(2.2)

This means you either have to work on float data, or 16 bit integer data. For proper WB balance, it is actually also a two-step process:

Remove WB compensation -> Apply new WB

So basicly you need to know the old WB. This is needed, because WB is not a linear/math based compensation, but a table of values based on measured values.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 26th January 2006, 01:44   #7  |  Link
SomeJoe
Registered User
 
Join Date: Jan 2003
Posts: 315
Hi sh0dan,

The source is included in the .zip file. The documentation also contains a detailed explaination of what the filter is doing.

Apparently, I've either not done enough (or done incorrect) research on white balance, or you and I aren't speaking of the same thing. Nothing I uncovered when I was writing this filter mentioned anything regarding gamma correction.

As I understand it, gamma is simply a measure of the non-linear brightness associated with monitor/TV phosphors, thus is a parameter affecting luminance. My WB filter doesn't make any changes to the luminance values of the frame (i.e. all Y values of the changed frame are identical to the source). So I'm not sure how a gamma adjustment/compensation would be necessary.

Nevertheless, I'm feeling more and more unsure of the filter. Communist (above) hasn't replied back regarding my suggestion for his material, but I was quite surprised that it didn't work well for him. In my tests, I did not have any of the issues he's showing, although his source material is a fairly extreme example. Perhaps there is a fundamental reason why the algorithm I'm using isn't correct, and if so, I'm at a loss. I was taught many years ago to white balance a video scene that was being shot with a video camera by using a vectorscope. You center the vectorscope's dot onto the white point by adjusting the white balance on the camera while it's pointed at a white card lit under the same lighting you're going to shoot under. The filter is just an electronic implementation of that.

If you have further insight, please let me know or point me to some references.
__________________
- SomeJoe
SomeJoe is offline   Reply With Quote
Old 30th January 2006, 13:24   #8  |  Link
communist
Registered User
 
Join Date: Jul 2003
Posts: 1,152
Sorry for the late reply.
I tried your values but not much luck with them. The problem with the footage might be that it is also not very stable over the time. So it might look good in a few frames but bad in others.
The best I got out of it is by using:
WhiteBalance(r1=160,g1=190,b1=220)


If you want you can take a look at the source (2,3 MB HuffYUV).
communist is offline   Reply With Quote
Old 2nd February 2006, 05:46   #9  |  Link
SomeJoe
Registered User
 
Join Date: Jan 2003
Posts: 315
Sorry for my late reply.

Thanks for your source, I downloaded it and I'm doing some tests.

There may be a bug in my math routines ... I will be checking them thoroughly ... stay tuned ...
__________________
- SomeJoe
SomeJoe is offline   Reply With Quote
Old 14th March 2006, 16:13   #10  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,718
Any news on this filter? I've got some stuff in which the white balance doesn't stay stable but the coloring goes from bluish to white and sometimes from yellowish to white to yellowish etc.

Or if anyone would like to have a go, I can upload some clips for testing.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 14th March 2006, 18:56   #11  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
try
http://acobw.narod.ru/acobw.html
Fizick is offline   Reply With Quote
Old 14th March 2006, 19:12   #12  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,718
I did but it crashed VDub 1.6.14 when previewing. Also the GUI is total gibberish as it's in Russian and the Cyrillic symbols don't even show up correctly on my PC
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 14th March 2006, 20:50   #13  |  Link
smok3
brontosaurusrex
 
smok3's Avatar
 
Join Date: Oct 2001
Posts: 2,392
Quote:
You center the vectorscope's dot onto the white point by adjusting the white balance on the camera while it's pointed at a white card lit under the same lighting you're going to shoot under. The filter is just an electronic implementation of that.
the original white balance on the camera happens after the CCD - in the electronic section of the camera - or should i say on cameras DSP path somewhere, so it is the same thing basically as your filter, but as sh0dan suggested it is applied to linear data and not on final curve (ok, i dont have a clue about coding so i dont know how would that translate to either RGB or YUV data, but i imagine you would have to reverse the UV part back to 'original stage' (or to approximately original stage) and then process that.)

a note: and CCD is linear device, i guess you could imagine that as sort of a foton counter maybe? - but the point is it doesnt see the world the same as eye (which is nonlinear).

p.s.
here is an example how some try to solve things in older photoshop versions:
http://www.adobeevangelists.com/pdfs...tByNumbers.pdf
(instead of getting the original curve - why not just adjust high, mid and low areas as separate..., hmm well )

Last edited by smok3; 14th March 2006 at 21:01.
smok3 is offline   Reply With Quote
Old 15th March 2006, 01:39   #14  |  Link
rfmmars
Registered User
 
Join Date: Feb 2004
Posts: 743
It does work

Quote:
Originally Posted by Boulder
I did but it crashed VDub 1.6.14 when previewing. Also the GUI is total gibberish as it's in Russian and the Cyrillic symbols don't even show up correctly on my PC
This is very good fillter but it does crash, but not always.

When it isn't going to work the bottom four sliders will snap back to zero. Reload and everything is ok.

What I do is to frameserve with this filter and only this filter in the chain to another copy of VD(xxx). Hope this plugin will be updated soon.

Richard
rfmmars is offline   Reply With Quote
Old 15th March 2006, 07:08   #15  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,718
I could try using it in Avisynth as soon as I can figure out some settings to try, maybe it'll be a bit more stable then. The GUI not being in English makes it hard though Maybe some Russian speaking person here could send the translations to the author?
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 15th March 2006, 16:00   #16  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,718
Or could someone (Fizick?) please post the parameters for using in Avisynth? Based on setting things randomly, the results look quite good but I'd like to know what I really am doing to the video
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 15th March 2006, 17:33   #17  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
I do not use it.
More info at:
http://forum.ixbt.com/topic.cgi?id=29:22283
(in Russian). I hope now you can imagine if all MY filter description would be in Russian only.
Fizick is offline   Reply With Quote
Old 15th March 2006, 21:10   #18  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,718
Quote:
Originally Posted by Fizick
I hope now you can imagine if all MY filter description would be in Russian only.
Well, I've never had any problems with your documentation. If I ever did, I would simply ask for clarification

The most important thing is that there at least is documentation, be it good or not so good, also the grammar isn't that important as you can easily assume and guess certain things if you're familiar with video processing.

I was thinking on the lines of someone pointing out what it says on the GUI. All I have is lots of question marks there:

__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...

Last edited by Boulder; 15th March 2006 at 21:13.
Boulder is offline   Reply With Quote
Old 16th March 2006, 11:21   #19  |  Link
Inc
Squeeze it!
 
Inc's Avatar
 
Join Date: Oct 2003
Location: Germany
Posts: 472
Hmmmm .....

Lets see, I got one "example" frame of a movie which represents the full luma range given of the whole movie.

In the source the luma range black-,medium- and white-balance is incorrect.



I added a manually generated Border to the right side where I used Photoshop to generate that incorrect-colored black/grey/white state where I used the pipette to catch the brightest and the darkest area out of the given representative frame.

This vertical bar can be imported as a pic into your avisynth script, converting to your matching colorspace, ... generate a clip using the same framecount.

Now there should be a way where ONLY the whitebalance is calculated out of THAT clip and finally applied to your movieclip.

The result will be this:



(I did stack horizontal the right border only for explaining).

This is just the approach by using photoshop. But the way could be included as routines in an avs-filter.

Last edited by Inc; 16th March 2006 at 11:28.
Inc is offline   Reply With Quote
Old 16th March 2006, 22:15   #20  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
I ask Sergey, he released English version AcobW today,
comments welcomed.
Fizick 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 20:27.


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