Log in

View Full Version : real and good frame by frame white balance function


greatfinders
1st May 2018, 11:56
Hello i explain myself, i am trying doing color correction for a while and i never find a good white balance plugin script for avisynth
i explain myself
i have r2j dvd having several tint issues , in after effect there is a good plugin called lumetri color that remove color cast just in one click but for avisynth all i find don't worth it

coloryuv(autowhite = true) is pure shit, the result is worst than the original
awb just make colors cold so you have a blue color cast on all the image

acobw and white balance for virtual dub are also shit (acobw just play with contrast and don't remove any color cast) and white balance result to a red color in the white


so i was wondering if someone build a good plugins that can do it frame by frame without tricking with luminosity brightness (cause it is destructive for details) and give a result that worth it

i have tried colormill for virtual dub but it's really a pain doing it manually and for each part of one episode

avisynth is great but i never understood why there isn't any valuable white balance plugins created

StainlessS
1st May 2018, 14:16
I did below for your previous disappearing thread.


Imagesource("180429020305179982.png").ConvertToRGB24
BicubicResize(640,480) # for forum post
O=last
GamMac() # all defaults
return StackVertical(o,Last)


https://s20.postimg.cc/4ak4nqq25/Gam_Mac_Toon.jpg (https://postimg.cc/image/bds03cvhl/)

GamMac():- http://forum.doom9.org/showthread.php?t=173695&highlight=gammac

EDIT: I used the beta version from near end of thread. (changed defaults of Th to 0.0)

greatfinders
1st May 2018, 14:41
That's my pb, all things i found only work for few part but not the whole things, one episode is cut into 7 part (as it seems the color cast is differrent in each part, sometimes the color cast change in the same part, it's a pain to color correct it, i have tried
coloryuv useless
awb make the things cold (blue filter)
this one don't work too that's why i was asking if a filter that can correct the white without destroying other things like here in the dark place , i know after effect have a plugin that play with hue and color temperature to make the white close to white (it should be grey but i don't know if a filter can do it)
https://nsa39.casimages.com/img/2018/05/01/180501034534245534.png


edit: rgbadapt also failed with it it remain yellow color cast

awb() give the most homogeneity result but it's blue filter (even the black color became have blue tint)

StainlessS
1st May 2018, 14:54
In above metrics,

IN: RED =0,169 G=9,149 B=15,166

Scale = 2, will expand lo and hi to OMin, OMax (default 0,255), [scale=2, is most 'severe' changes]
Scale=2 stretches all 3 channels to min max (separately).
So, Scale=2,
R 169 stretched up to 255
G 9 to 0, 149 to 255
B 15 to 0, 166 to 255.

Scale=1, would stretch lowest low (n this case 0) goes to 0, highest hi (in this case 169) goes to 255 (169->255 for all 3 channels).
Suggest try Scale = 1, (or Scale=0) instead.
(Scale=0, does no stretching, just adjusts gamma for each channel)

EDIT: In actual fact, I think above result is pretty damn good (although somewhat lumpy), if it did
suffer from colour caste, it cleaned it up pretty good, its just that in that case it was supposed to look as if colour casted.
Looks to me like it might have started out somewhat like the above corrected frame, but was then darkened with some
color caste in most areas, to simulate a night scene.

EDIT: Also, if not using the lastest beta with default Th=0, then suggest also set Th=0.0.

StainlessS
1st May 2018, 15:27
Imagesource("180501034534245534.png").ConvertToRGB24
Crop(0,0,0,height/2)
BicubicResize(640,480) # for forum post
O=last
GamMac(Scale=0,Th=0.0,verbosity=4)
return StackVertical(o,Last)


https://s20.postimg.cc/4i7rjw625/Copy_of_A.jpg (https://postimg.cc/image/7cawxc889/)

Not brilliant, but maybe better for your need.
I guess you have to decide whether you do, or dont want to remove color castes.

EDIT:
I guess for speed, you could knock up a script for Sawbones using multiple clips (scale=2, scale=1, scale=0 + maybe others),
showing in SawBones as a mult-windowed clip).
And in Sawbones viewing your multi-window clip, select a range and an FX window clip (pre-prefiltered clip).
So, could assign different setting to different sections of your clip, easily.
SawBones/FrameSurgeon supports up to 9 FX clips (plus source).
There are several demos in Sawbones / FrameSurgeon.

Sawbones/FrameSurgeon demo script

Import("../FrameSurgeon.avs")

### Config #############################################
FINAL=False # Change to TRUE to do real DELETES (FALSE only shows where deletes would occur, ALWAYS use FALSE with SawBones)
### One of below strings
SCMD=""" # Demo Test
CP 100 # CP, Single frame args ONLY. Replace 100 with frame 99.
CN 101 # CN, Single frame args ONLY. REplace 101 with frame 102.
I9 110 # Id, Single frame args ONLY. Interpolate 9 frames starting at frame 110.
FX1 200,299 # Replace 200->299 with same range from FX1 clip. (FXd clips default source if not supplied, Subtitled if Show)
FX2 300,399
FX3 400,499
FX4 500,-50 # Replace 50 frames starting at 500.
FX5 550,-50 # Replace 50 frames starting at 550. NOTE, as not defined in this script FX5 defaults Subtitled source clip.
FX6 600,-100 # Replace 100 frames starting at 600. NOTE, as not defined in this script FX6 defaults Subtitled source clip.
FX7 700,-100 # Replace 100 frames starting at 700. NOTE, as not defined in this script FX7 defaults Subtitled source clip.
DEL 800,899
DEL 900,-100 # Del 100 frames starting from 900
DEL 2000,0 # Del from 2000 to end of clip.
"""
#SCMD=""

### One of below strings (CMD file is processed before SCMD, where multiple replacements on same frame)
CMD="FrameSurgeon_DEMO_Cmd.TXT" # Command file, perhaps created via SawBones.
#CMD = ""

SHOW=!FINAL # Show ClipClop OR Prune Metrics
SHOWMODE=0 # 0=ClipClop metrics, 1=Prune Metrics (Show remaining after deletions rather than replacements)
DV=4 # 0=ERRORS ONLY, 4=FULL Debug to DebugView(Google)
NOERR=False # Set True if wanting to IGNORE FXd commands for undefined FXd clips.

# MvTools, Interpolate args (see mvTools)
PEL=2
SHARP=2
RFILTER=2
ML=100.0
#
STACK=(!FINAL || SHOW) # Auto stack window OFF when FINAL==True and SHOW==FALSE
########################################################

### Source clip ###
src=Colorbars.killaudio.ConvertToYV12
src=src.ShowFrameNumber(Size=src.Height/6,x=src.Width/2,y=src.Height/3)

### Simulated replacement clips ###
FX1 = src.FlipVertical
FX2 = src.FlipHorizontal
FX3 = src.Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58)
FX4 = src.Sharpen(1.0).Sharpen(1.0).Sharpen(1.0)

### Edit or No Edit ###
CMD=(CMD!="") ? RT_GetFullPathName(CMD) : ""
PROCESS = (SCMD!="" || (CMD!="" && Exist(CMD))) # Skip FrameSurgeon if no String nor file commands (yet).

Result = (PROCESS)
\ ? FrameSurgeon(src,scmd=SCMD,cmd=CMD,Show=Show,ShowMode=SHOWMODE,dv=DV,
\ fx1=FX1,fx2=FX2,fx3=FX3,fx4=FX4,
\ pel=PEL,sharp=SHARP,rfilter=RFILTER,ml=ML,
\ Final=FINAL,NoErr=NOERR)
\ : src

### Stack For View ###
BSZ=4 BCOL=$FF00FF
Ssrc=src.RtSub("Source",True) SFX1=FX1.RtSub("FX1",True) SFX2=FX2.RtSub("FX2",True)
SFX3=FX3.RtSub("FX3",True) SFX4=FX4.RtSub("FX4",True) SResult=Result.RtSub("Result",True)
TOP=StackHorizontal(Ssrc,Ssrc.BlankClip(width=BSZ,Color=BCOL),SFX1,Ssrc.BlankClip(width=BSZ,Color=BCOL),SFX2)
BOT=StackHorizontal(SFX3,Ssrc.BlankClip(width=BSZ,Color=BCOL),SFX4,Ssrc.BlankClip(width=BSZ,Color=BCOL),SResult)
(STACK) ? StackVertical(TOP,TOP.BlankClip(height=BSZ,Color=BCOL),BOT) : Result
Return Last.Spline36Resize(960,640)

# Stack Overhead RT_Subtitle Text, with optional FrameNumber shown.
Function RtSub(clip c,string Tit, Bool "ShowFrameNo") {
c.BlankClip(height=20)
(Default(ShowFrameNo,False)) ? ScriptClip("""RT_Subtitle("%d] %s",current_frame,""""+Tit+"""")""") : RT_Subtitle("%s",Tit)
Return StackVertical(c).AudioDubEx(c)
}

https://s20.postimg.cc/62how8tm5/Frame_Surgeon_DEMO.jpg (https://postimages.org/)
EDIT: Replaced script and image with better demo version.

So from in sawbones (Uses VirtualDub2 as viewer), you can mark section, and press key sequence to use the prefiltered FXn clip for that section.
Easy Peasy.
EDIT: If you press the save and refresh key sequence, it will do the edit and show result (as in above, bottom right window).
EDIT: For sections like the night scene, just dont assign any clip, ie use the original source or some other prefiltering.

and below showing delted frames range (not really deleted until FINAL=True when rendering.

https://s20.postimg.cc/i4d2qokxp/Frame_Surgeon_DEMO.jpg (https://postimages.org/)

Stereodude
1st May 2018, 15:30
Hello i explain myself, i am trying doing color correction for a while and i never find a good white balance plugin script for avisynth
Probably because it's not really possible within the scope of AVIsynth. With some sort of machine learning and huge databases of source content for the algorithms to learn from it might be possible to make some sort of "AI" based automatic color correction but that's probably well beyond what can be done in AVIsynth.

greatfinders
1st May 2018, 15:39
Probably because it's not really possible within the scope of AVIsynth. With some sort of machine learning and huge databases of source content for the algorithms to learn from it might be possible to make some sort of "AI" based automatic color correction but that's probably well beyond what can be done in AVIsynth.

okay that's what i was suspecting so i'll do it with after effect, it's not perfect either but it can be done in one click so far easier for me

thanks stainless, you pointed a good things, no script can describe what is night or day things and i am probably dreaming doing it automatically, it can work for short clip or if you did manually for each part but it's way too longest for me

LemMotlow
1st May 2018, 15:50
GamMac doesn't look all that automatic (all you have to do is figure out the programmed process algorithms and how to change them). From orther posts I see that if the lighting changes or some other object enters a scene, or the camera pans over, etc., the color balance changes -- just like other AGC controls. In my own case what I get is output that looks exactly like the input.

In other words, you have to know at least some basic color and levels theory to use anything "automatic". Those auto filters are a cop-out from learning something about what the heck is going on.

poisondeathray
1st May 2018, 16:07
(And it's not quite automatic in lumetri color either , and scene differences can cause problems there too)

greatfinders
1st May 2018, 17:00
(And it's not quite automatic in lumetri color either , and scene differences can cause problems there too)

yes i know , anyway with after effect i have to trim each episode by part that was store on differrent film and did a lossless encode before as authoring issues can't be solve by adobe software (that's why i wanted to have the same process with avisynth to make me doing one encode for everythings

in few rare case like flashback or few episodes, you have differrent color cast so only to cut by part with avisynth , then pointed each part with this filter, doing the same with color neutralizer for grey and black point (caused the black color also have tint) then doing final encode that merged files into one color corrected

in avisynth doing this adjustment manually is FAAAAARRRRRR too much time consuming, it's pretty nice when you have few videos or that you play with videos that was stored on the same VHS but in this case it can't help me

i tried color mill that is a very good way to color balance too but settings it for each part is a hell and not perfect either , too much option to settle manually and you will easilly loose yourself into them

i was thinking as selective colour plugin from after effect was coded into avisynth , that lumetri could have been done too or that someone create another kind of white balance function that work pretty nice
but it doesn't seems something like that exist

it's like lut that you can't use in avisynth

greatfinders
1st May 2018, 17:04
Imagesource("180501034534245534.png").ConvertToRGB24
Crop(0,0,0,height/2)
BicubicResize(640,480) # for forum post
O=last
GamMac(Scale=0,Th=0.0,verbosity=4)
return StackVertical(o,Last)


https://s20.postimg.cc/4i7rjw625/Copy_of_A.jpg (https://postimg.cc/image/7cawxc889/)

Not brilliant, but maybe better for your need.
I guess you have to decide whether you do, or dont want to remove color castes.

EDIT:
I guess for speed, you could knock up a script for Sawbones using multiple clips (scale=2, scale=1, scale=0 + maybe others),
showing in SawBones as a mult-windowed clip).
And in Sawbones viewing your multi-window clip, select a range and an FX window clip (pre-prefiltered clip).
So, could assign different setting to different sections of your clip, easily.
SawBones/FrameSurgeon supports up to 9 FX clips (plus source).
There are several demos in Sawbones / FrameSurgeon.

Sawbones/FrameSurgeon demo script

Import("../FrameSurgeon.avs")

### Config #############################################
FINAL=False # Change to TRUE to do real DELETES (FALSE only shows where deletes would occur, ALWAYS use FALSE with SawBones)
### One of below strings
SCMD=""" # Demo Test
CP 100 # CP, Single frame args ONLY. Replace 100 with frame 99.
CN 101 # CN, Single frame args ONLY. REplace 101 with frame 102.
I9 110 # Id, Single frame args ONLY. Interpolate 9 frames starting at frame 110.
FX1 200,299 # Replace 200->299 with same range from FX1 clip. (FXd clips default source if not supplied, Subtitled if Show)
FX2 300,399
FX3 400,499
FX4 500,-50 # Replace 50 frames starting at 500.
FX5 550,-50 # Replace 50 frames starting at 550. NOTE, as not defined in this script FX5 defaults Subtitled source clip.
FX6 600,-100 # Replace 100 frames starting at 600. NOTE, as not defined in this script FX6 defaults Subtitled source clip.
FX7 700,-100 # Replace 100 frames starting at 700. NOTE, as not defined in this script FX7 defaults Subtitled source clip.
DEL 800,899
DEL 900,-100 # Del 100 frames starting from 900
DEL 2000,0 # Del from 2000 to end of clip.
"""
#SCMD=""

### One of below strings (CMD file is processed before SCMD, where multiple replacements on same frame)
CMD="FrameSurgeon_DEMO_Cmd.TXT" # Command file, perhaps created via SawBones.
#CMD = ""

SHOW=!FINAL # Show ClipClop OR Prune Metrics
SHOWMODE=0 # 0=ClipClop metrics, 1=Prune Metrics (Show remaining after deletions rather than replacements)
DV=4 # 0=ERRORS ONLY, 4=FULL Debug to DebugView(Google)
NOERR=False # Set True if wanting to IGNORE FXd commands for undefined FXd clips.

# MvTools, Interpolate args (see mvTools)
PEL=2
SHARP=2
RFILTER=2
ML=100.0
#
STACK=(!FINAL || SHOW) # Auto stack window OFF when FINAL==True and SHOW==FALSE
########################################################

### Source clip ###
src=Colorbars.killaudio.ConvertToYV12
src=src.ShowFrameNumber(Size=src.Height/6,x=src.Width/2,y=src.Height/3)

### Simulated replacement clips ###
FX1 = src.FlipVertical
FX2 = src.FlipHorizontal
FX3 = src.Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58)
FX4 = src.Sharpen(1.0).Sharpen(1.0).Sharpen(1.0)

### Edit or No Edit ###
CMD=(CMD!="") ? RT_GetFullPathName(CMD) : ""
PROCESS = (SCMD!="" || (CMD!="" && Exist(CMD))) # Skip FrameSurgeon if no String nor file commands (yet).

Result = (PROCESS)
\ ? FrameSurgeon(src,scmd=SCMD,cmd=CMD,Show=Show,ShowMode=SHOWMODE,dv=DV,
\ fx1=FX1,fx2=FX2,fx3=FX3,fx4=FX4,
\ pel=PEL,sharp=SHARP,rfilter=RFILTER,ml=ML,
\ Final=FINAL,NoErr=NOERR)
\ : src

### Stack For View ###
BSZ=4 BCOL=$FF00FF
Ssrc=src.RtSub("Source",True) SFX1=FX1.RtSub("FX1",True) SFX2=FX2.RtSub("FX2",True)
SFX3=FX3.RtSub("FX3",True) SFX4=FX4.RtSub("FX4",True) SResult=Result.RtSub("Result",True)
TOP=StackHorizontal(Ssrc,Ssrc.BlankClip(width=BSZ,Color=BCOL),SFX1,Ssrc.BlankClip(width=BSZ,Color=BCOL),SFX2)
BOT=StackHorizontal(SFX3,Ssrc.BlankClip(width=BSZ,Color=BCOL),SFX4,Ssrc.BlankClip(width=BSZ,Color=BCOL),SResult)
(STACK) ? StackVertical(TOP,TOP.BlankClip(height=BSZ,Color=BCOL),BOT) : Result
Return Last.Spline36Resize(960,640)

# Stack Overhead RT_Subtitle Text, with optional FrameNumber shown.
Function RtSub(clip c,string Tit, Bool "ShowFrameNo") {
c.BlankClip(height=20)
(Default(ShowFrameNo,False)) ? ScriptClip("""RT_Subtitle("%d] %s",current_frame,""""+Tit+"""")""") : RT_Subtitle("%s",Tit)
Return StackVertical(c).AudioDubEx(c)
}

https://s20.postimg.cc/62how8tm5/Frame_Surgeon_DEMO.jpg (https://postimages.org/)
EDIT: Replaced script and image with better demo version.

So from in sawbones (Uses VirtualDub2 as viewer), you can mark section, and press key sequence to use the prefiltered FXn clip for that section.
Easy Peasy.
EDIT: If you press the save and refresh key sequence, it will do the edit and show result (as in above, bottom right window).
EDIT: For sections like the night scene, just dont assign any clip, ie use the original source or some other prefiltering.

and below showing delted frames range (not really deleted until FINAL=True when rendering.

https://s20.postimg.cc/i4d2qokxp/Frame_Surgeon_DEMO.jpg (https://postimages.org/)

didn't see this before but it's too much complicated for me lol i am not as strong as you and it is not really the things i wanted to do as it is not really automatic but thanks for the explanation and the help

poisondeathray
1st May 2018, 17:06
i was thinking as selective colour plugin from after effect was coded into avisynth , that lumetri could have been done too or that someone create another kind of white balance function that work pretty nice
but it doesn't seems something like that exist

But this requires some type of GUI and user interaction, eye dropper to add/subtract samples, modify inclusion/exclusion areas or colors. Doesn't sound like avisynth to me.

There are crude ways with masks like maskhs() and variations on hue/saturation masks with masktools . Not as elegant or interactive

They are just different tool sets



it's like lut that you can't use in avisynth

There is a lut plugin for vapoursynth . You can request a port.

Currently you can import vpy scripts into avs (but there some are limitations, you won't be able to import float for example)