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 21st May 2014, 04:10   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
RGBAdapt v0.3 plugin 17 June 2015

Code:
RGBAdapt v0.3, By StainlessS

For Avisynth v2.58+

RGB24/RGB32.
Audio as original.

RGBAdapt(clip c, \
    \ Float "R_Bias"=0.0,Float "R_Gain"=1.0,Float "R_Cont"=1.0,Float "R_RPow"=1.0,Float "R_Spow"=1.0,Float "R_SPMid"=0.5,Bool "R_Pord"=false,
    \ Float "G_Bias"=0.0,Float "G_Gain"=1.0,Float "G_Cont"=1.0,Float "G_RPow"=1.0,Float "G_Spow"=1.0,Float "G_SPMid"=0.5,Bool "G_Pord"=false,
    \ Float "B_Bias"=0.0,Float "B_Gain"=1.0,Float "B_Cont"=1.0,Float "B_RPow"=1.0,Float "B_Spow"=1.0,Float "B_SPMid"=0.5,Bool "B_Pord"=false,
    \ Int "R_IMin"=0,Int "R_OMin"=0,Int "R_IMax"=255,Int "R_OMax"=255,
    \ Int "G_IMin"=0,Int "G_OMin"=0,Int "G_IMax"=255,Int "G_OMax"=255,
    \ Int "B_IMin"=0,Int "B_OMin"=0,Int "B_IMax"=255,Int "B_OMax"=255
    \ )

Bias    -512.0 -> 512.0.                Bias = Brightness. 
Gain    -8.0   -> 8.0                   Gain = Zero relative contrast.
Cont    -8.0   -> 8.0                   Cont = Centre relative Contrast.
RPow    0.1    -> 4.0                   RPow = Gamma, r shaped power curve.
SPow    0.1    -> 4.0                   SPow = S shaped power curve.
SPMid   0.01   -> 0.99                  SPMid = Controls Inflection point for S shaped power curve, 0.5 = mid point ie 0.5*255.0
Pord    True/False                      Pord=Rpow processed first (False) or SPow first (True). The power functions are non commutative.

    Assuming all settings apart from RPow, SPow and SPMid at defaults:-
     Pord Default (false) RPow1st, when modifying RPow or SPow, the SPow power curve inflection point will
    remain fixed at Y = SPMid * 255.0, Rpow will slide it left or right.
     Pord SPow1st, when modifying RPow or SPow, the SPow power curve inflection point will remain fixed
    at X = SPMid * 255.0, RPow will slide it up or down.

New args v0.3
IMin    0 -> 255 : IMin <= (IMax+1)
OMin    0 -> 255
IMax    0 -> 255 : (IMin-1) <= IMax
OMax    0 -> 255

 Any INPUT value less than IMin will be mapped to OMin (both default to 0), and values greater than IMax will be mapped to
OMax (both default to 255). With default settings the Min/Max options have no effect. 
These options allow for weird shaped LUT's to eg create masks. Example, Leaving all other settings at default and
for some channel set IMax to eg 127 and OMax to 64 would map all input above 127 to 64 while leaving everything else untouched.
If you additionally set eg IMin=128 and OMin=180, then 0-127 would map to 180 and 128->255 map to 64.
The IMin <= (IMax+1) requirement allows you to map the entire 0->255 range to any two output values.

  

RgbAdapt_Graffer.exe demos the plugin and all arguments. (Will require VB6 runtimes, most will already have these.)
Code:
 v0.1, fixed float to double conversion (0.1 -> 0.999999 etc)
 v0.2, Copies RGB32 Alpha channel rather than zero.
 v0.3, Added Imin,OMin, IMax and OMax args.
And here a pic of the Graffer:-


The Ring on the Fish's cheek shows the pixel that is being tracked and the Before and After colors shown in status bar.
Monitor changes for single pixel as you modify the sliders.
The tick box on left show that SPow is locked so R + G + B settings are affected simultaneously.

From doc
Quote:
Assuming all settings apart from RPow, SPow and SPMid at defaults:-
Pord Default (false) RPow1st, when modifying RPow or SPow, the SPow power curve inflection point will
remain fixed at Y = SPMid * 255.0, Rpow will slide it left or right.
As Pord RPow1st and SPMid @ 0.5 so SPow inflection point is fixed at Y = 0.5 * 255.0 for all three channels, and
as all three channels have SPow @ 1.18, the differing channels values of RPow shift it left or right as in graph.

Click on MediaFire below.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 15th July 2017 at 18:49. Reason: Update
StainlessS is offline   Reply With Quote
Old 22nd May 2014, 18:11   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
Minor update, v0.1, see previous post.

Added LumaSceneChange_Graffer to demo functionality, looks like this:

EDIT: LumaSceneChange_Graffer removed, new graffer included see here:- http://forum.doom9.org/showthread.ph...92#post1726292
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th June 2015 at 22:26.
StainlessS is offline   Reply With Quote
Old 23rd May 2014, 19:19   #3  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hello StainlessS

Your plugin is great.

Thus i have tried to use it for auto white balance.
Code:
AVISource("C:\....\video.avi")

LoadPlugin("C:\..................\RGBAdapt_dll_v0.1-20140522\RGBAdapt.dll")

threshold = [<"threshold", 0, 255, 127>]
divisor_bias = [<"divisor_bias", 1, 10, 2>]
divisor_rpow = [<"divisor_rpow", 50, 150, 100>]
divisor_spow = [<"divisor_spow", 50, 150, 150>]


ConvertToRGB32(matrix="Rec601")

a=last

neutre = BlankClip(a, pixel_type="RGB32", color=$000000)

red=a.ShowRed("RGB32")
green = a.ShowGreen("RGB32")
blue = a.ShowBlue("RGB32")

b=a.ScriptClip("""
    r = RGBDifference(red,neutre)
    g = RGBDifference(green,neutre)
    b = RGBDifference(blue,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    dr1 = (threshold - r)*1/divisor_bias
    dg1 = (threshold - g)*1/divisor_bias
    db1 = (threshold - b)*1/divisor_bias       
    RGBAdapt( \
     R_Bias = dr1, R_Gain = 1.0, R_Cont = 1.0, R_RPow = 1.0, R_Spow = 1.0, R_SPMid = 0.5, R_Pord = false, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = 1.0, G_RPow = 1.0, G_Spow = 1.0, G_SPMid = 0.5, G_Pord = false,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = 1.0, B_RPow = 1.0, B_Spow = 1.0, B_SPMid = 0.5, B_Pord = false)
""")

red2=b.ShowRed("RGB32")
green2 = b.ShowGreen("RGB32")
blue2 = b.ShowBlue("RGB32")

c=b.ScriptClip("""
    r = RGBDifference(red2,neutre)
    g = RGBDifference(green2,neutre)
    b = RGBDifference(blue2,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    yr = 1+(threshold - r)*1/divisor_rpow
    yg = 1+(threshold - g)*1/divisor_rpow
    yb = 1+(threshold - b)*1/divisor_rpow        
    RGBAdapt( \
     R_Bias = 0.0, R_Gain = 1.0, R_Cont = 1.0, R_RPow = yr, R_Spow = 1.0, R_SPMid = 0.5, R_Pord = false, \
	 G_Bias = 0.0, G_Gain = 1.0, G_Cont = 1.0, G_RPow = yg, G_Spow = 1.0, G_SPMid = 0.5, G_Pord = false,\
	 B_Bias = 0.0, B_Gain = 1.0, B_Cont = 1.0, B_RPow = yb, B_Spow = 1.0, B_SPMid = 0.5, B_Pord = false)
""") 

red3=c.ShowRed("RGB32")
green3 = c.ShowGreen("RGB32")
blue3 = c.ShowBlue("RGB32")

d=c.ScriptClip("""
    r = RGBDifference(red3,neutre)
    g = RGBDifference(green3,neutre)
    b = RGBDifference(blue3,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    sr = 1-(threshold - r)*1/divisor_spow
    sg = 1-(threshold - g)*1/divisor_spow
    sb = 1-(threshold - b)*1/divisor_spow
    RGBAdapt(c, \
     R_Bias = 0.0, R_Gain = 1.0, R_Cont = 1.0, R_RPow = 1.0, R_Spow = sr, R_SPMid = 0.5, R_Pord = false, \
	 G_Bias = 0.0, G_Gain = 1.0, G_Cont = 1.0, G_RPow = 1.0, G_Spow = sg, G_SPMid = 0.5, G_Pord = false,\
	 B_Bias = 0.0, B_Gain = 1.0, B_Cont = 1.0, B_RPow = 1.0, B_Spow = sb, B_SPMid = 0.5, B_Pord = false)           
""") 
	 
StackHorizontal(a.Subtitle("original"),b.Subtitle("linear curve"),c.Subtitle("Rpow curve"),d.Subtitle("Spow curve"),a.ConvertToYV12.ColorYUV(autowhite=true).Subtitle("AWB ColorYUV").ConvertToRGB32)
It is auto, but I have put some variable values for test.

Has this script a sense ? Has Bias and Rpow auto-tune a sense ? Has Rpow and Spow auto-tune a sense ?

For the last question, i think no, but for the other i don't know yet.

Thanks

Last edited by Bernardd; 23rd May 2014 at 20:28.
Bernardd is offline   Reply With Quote
Old 24th May 2014, 22:13   #4  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hello,

I have worked this day on RGBAdapt use for automatic white balance. I have found a new expression to tune Rpow and Spow. Perhaps is it a best expression, but i have not found it this day.

Now the script is OK for me.
Code:
AVISource("C:\.......\1970-1971-Noel-Ski début rayures et poussières amoindries.avi")

LoadPlugin("C:\..............\RGBAdapt_dll_v0.1-20140522\RGBAdapt.dll")

info = [<"info", 0, 1, 1>] # show info, no = 0, yes = 1
threshold = [<"threshold", 0, 255, 127>]
divisor_bias = [<"divisor_bias", 0.1, 1.0, 0.5>]

ConvertToRGB32(matrix="Rec601")

a=last

neutre = BlankClip(a, pixel_type="RGB32", color=$000000)

#---------------------------------------- Linear curve b with info, b1 without info

red=a.ShowRed("RGB32")
green = a.ShowGreen("RGB32")
blue = a.ShowBlue("RGB32")
 
b=a.ScriptClip("""
    r = RGBDifference(red,neutre)
    g = RGBDifference(green,neutre)
    b = RGBDifference(blue,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    dr1 = dr*divisor_bias
    dg1 = dg*divisor_bias
    db1 = db*divisor_bias
    Subtitle("Red value : "+String(r)+"Bias : "+String(dr1),y=40)
    Subtitle("Green value : "+String(b)+"Bias : "+String(dg1),y=60)
    Subtitle("Blue value : "+String(b)+"Bias : "+String(db1),y=80)      
    RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = 1.0, R_RPow = 1.0, R_Spow = 1.0, R_SPMid = 0.5, R_Pord = true, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = 1.0, G_RPow = 1.0, G_Spow = 1.0, G_SPMid = 0.5, G_Pord = true,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = 1.0, B_RPow = 1.0, B_Spow = 1.0, B_SPMid = 0.5, B_Pord = true)
""")

b1=a.ScriptClip("""
    r = RGBDifference(red,neutre)
    g = RGBDifference(green,neutre)
    b = RGBDifference(blue,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    dr1 = dr*divisor_bias
    dg1 = dg*divisor_bias
    db1 = db*divisor_bias        
    RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = 1.0, R_RPow = 1.0, R_Spow = 1.0, R_SPMid = 0.5, R_Pord = true, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = 1.0, G_RPow = 1.0, G_Spow = 1.0, G_SPMid = 0.5, G_Pord = true,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = 1.0, B_RPow = 1.0, B_Spow = 1.0, B_SPMid = 0.5, B_Pord = true)
""")

#---------------------------------------- Rpow curve c with info, c1 without info

red2=b1.ShowRed("RGB32")
green2 = b1.ShowGreen("RGB32")
blue2 = b1.ShowBlue("RGB32")

c=b1.ScriptClip("""
    r = RGBDifference(red2,neutre)
    g = RGBDifference(green2,neutre)
    b = RGBDifference(blue2,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    m=(dr+dg+db)     
    yr = (dr < 0) ? 1+dr/100:1+dr/100 
    yg = (dg < 0) ? 1+dg/100:1+dg/100 
    yb = (db < 0) ? 1+db/100:1+db/100     
    Subtitle("Red value : "+String(r)+"Bias : "+String(dr)+" Rpow : "+String(yr),y=40)
    Subtitle("Green value : "+String(b)+"Bias : "+String(dg)+" Rpow : "+String(yg),y=60)
    Subtitle("Blue value : "+String(b)+"Bias : "+String(db)+" Rpow : "+String(yb),y=80)       
    RGBAdapt( \
    R_Bias = 0.0, R_Gain = 1.0, R_Cont = 1.0, R_RPow = yr, R_Spow = 1.0, R_SPMid = 0.5, R_Pord = true, \
	 G_Bias = 0.0, G_Gain = 1.0, G_Cont = 1.0, G_RPow = yg, G_Spow = 1.0, G_SPMid = 0.5, G_Pord = true,\
	 B_Bias = 0.0, B_Gain = 1.0, B_Cont = 1.0, B_RPow = yb, B_Spow = 1.0, B_SPMid = 0.5, B_Pord = true)
""")
 
c1=b1.ScriptClip("""
    r = RGBDifference(red2,neutre)
    g = RGBDifference(green2,neutre)
    b = RGBDifference(blue2,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    m=(dr+dg+db)     
    yr = (dr < 0) ? 1+dr/100:1+dr/100
    yg = (dg < 0) ? 1+dg/100:1+dg/100
    yb = (db < 0) ? 1+db/100:1+db/100          
    RGBAdapt( \
    R_Bias = 0.0, R_Gain = 1.0, R_Cont = 1.0, R_RPow = yr, R_Spow = 1.0, R_SPMid =  0.5, R_Pord = true, \
	 G_Bias = 0.0, G_Gain = 1.0, G_Cont = 1.0, G_RPow = yg, G_Spow = 1.0, G_SPMid = 0.5, G_Pord = true,\
	 B_Bias = 0.0, B_Gain = 1.0, B_Cont = 1.0, B_RPow = yb, B_Spow = 1.0, B_SPMid = 0.5, B_Pord = true)
""") 

#---------------------------------------- Spow curve d with info, d1 without info

red3=c1.ShowRed("RGB32")
green3 = c1.ShowGreen("RGB32")
blue3 = c1.ShowBlue("RGB32")

d=c1.ScriptClip("""
    r = RGBDifference(red3,neutre)
    g = RGBDifference(green3,neutre)
    b = RGBDifference(blue3,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    sr = (dr < 0) ? 1+dr/100:1+dr/100
    sg = (dg < 0) ? 1+dg/100:1+dg/100
    sb = (db < 0) ? 1+db/100:1+db/100   
    Subtitle("Red value : "+String(r)+"Bias : "+String(dr)+" Spow : "+String(sr),y=40)
    Subtitle("Green value : "+String(b)+"Bias : "+String(dg)+" Spow : "+String(sg),y=60)
    Subtitle("Blue value : "+String(b)+"Bias : "+String(db)+" Spow : "+String(sb),y=80)
    RGBAdapt( \
    R_Bias = 0.0, R_Gain = 1.0, R_Cont = 1.0, R_RPow = 1.0, R_Spow = sr, R_SPMid = 0.5, R_Pord = false, \
	 G_Bias = 0.0, G_Gain = 1.0, G_Cont = 1.0, G_RPow = 1.0, G_Spow = sg, G_SPMid = 0.5, G_Pord = false,\
	 B_Bias = 0.0, B_Gain = 1.0, B_Cont = 1.0, B_RPow = 1.0, B_Spow = sb, B_SPMid = 0.5, B_Pord = false)           
""") 

d1=c1.ScriptClip("""
    r = RGBDifference(red3,neutre)
    g = RGBDifference(green3,neutre)
    b = RGBDifference(blue3,neutre)
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    sr = (dr < 0) ? 1+dr/100:1+dr/100
    sg = (dg < 0) ? 1+dg/100:1+dg/100
    sb = (db < 0) ? 1+db/100:1+db/100
    RGBAdapt( \
    R_Bias = 0.0, R_Gain = 1.0, R_Cont = 1.0, R_RPow = 0.9, R_Spow = sr, R_SPMid = 0.5, R_Pord = false, \
	 G_Bias = 0.0, G_Gain = 1.0, G_Cont = 1.0, G_RPow = 0.9, G_Spow = sg, G_SPMid = 0.5, G_Pord = false,\
	 B_Bias = 0.0, B_Gain = 1.0, B_Cont = 1.0, B_RPow = 0.9, B_Spow = sb, B_SPMid = 0.5, B_Pord = false)           
""")

(info == 1) ? \	 
StackHorizontal(a.Subtitle("original"),b.Subtitle("linear curve"),c.Subtitle("Rpow curve"),d.Subtitle("Spow curve"),\
                               a.ConvertToYV12.ColorYUV(autowhite=true).Subtitle("AWB ColorYUV").ConvertToRGB32) : \
StackHorizontal(a.Subtitle("original"),b1.Subtitle("linear curve"),c1.Subtitle("Rpow curve"),d1.Subtitle("Spow curve"),\
                               a.ConvertToYV12.ColorYUV(autowhite=true).Subtitle("AWB ColorYUV").ConvertToRGB32)
Thanks for the plugin. With Rpow and Spow use i have a best result that RGBAdjust and gamma use.

Last edited by Bernardd; 24th May 2014 at 22:15.
Bernardd is offline   Reply With Quote
Old 25th May 2014, 10:35   #5  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hello StainlessS,

After night, ideas are more light, thus i have written still my script for having more accordance with your great plugin.
Code:
AVISource("C:\.......\video.avi")

LoadPlugin("C:\......\RGBAdapt_dll_v0.1-20140522\RGBAdapt.dll")

threshold = [<"threshold", 0, 255, 127>] # Middle ton for automatic white balance
strength_bias = [<"strength_bias", 0.1, 1.0, 0.5>] # Strength linear curve use
strength_Rpow = [<"Strength_Rpow", 0.1, 1.0, 0.8>]  # Strength Rpow curve use
strength_Spow = [<"Strength_Spow", 0.1, 1.0, 1.0>] # Strength Spow curve use

ConvertToRGB32(matrix="Rec601")

a=last

neutre = BlankClip(a, pixel_type="RGB32", color=$000000)

#---------------------------------------- Linear curve b with info, b1 without info

red=a.ShowRed("RGB32")
green = a.ShowGreen("RGB32")
blue = a.ShowBlue("RGB32")
 
b=a.ScriptClip("""
    
#------------ RGB values calcul
    r = RGBDifference(red,neutre)
    g = RGBDifference(green,neutre)
    b = RGBDifference(blue,neutre)
    
#----------- RGB correction calcul    
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    
#-----------  RGB correction with linear curve calcul (Bias)   
    dr1 = dr*strength_bias
    dg1 = dg*strength_bias
    db1 = db*strength_bias
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dr2 = dr-dr1
    dg2 = dg-dg1
    db2 = db-db1
    
#-----------  RGB correction with Rpow curve calcul        
    yr = (dr2 < 0) ? (1+dr2/100)*strength_rpow:(1+dr2/100)*strength_rpow 
    yg = (dg2 < 0) ? (1+dg2/100)*strength_rpow:(1+dg2/100)*strength_rpow 
    yb = (db2 < 0) ? (1+db2/100)*strength_rpow:(1+db2/100)*strength_rpow
    
#-----------  RGB correction with Spow curve calcul    
    sr = (dr2 < 0) ? (1+dr2/100)*strength_spow:(1+dr2/100)*strength_spow
    sg = (dg2 < 0) ? (1+dg2/100)*strength_spow:(1+dg2/100)*strength_spow
    sb = (db2 < 0) ? (1+db2/100)*strength_spow:(1+db2/100)*strength_spow
         
    Subtitle("Red value : "+String(r)+"Bias : "+String(dr)+" Rpow : "+String(yr)+" Spow : "+String(sr),y=40)
    Subtitle("Green value : "+String(b)+"Bias : "+String(dg)+" Rpow : "+String(yg)+" Spow : "+String(sg),y=60)
    Subtitle("Blue value : "+String(b)+"Bias : "+String(db)+" Rpow : "+String(yb)+" Spow : "+String(sb), y=80)      
    
    RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = 1.0, R_RPow = yr, R_Spow = sr, R_SPMid = 0.5, R_Pord = false, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = 1.0, G_RPow = yg, G_Spow = sg, G_SPMid = 0.5, G_Pord = false,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = 1.0, B_RPow = yb, B_Spow = sb, B_SPMid = 0.5, B_Pord = false)
""")

b1=a.ScriptClip("""

#------------ RGB values calcul
    r = RGBDifference(red,neutre)
    g = RGBDifference(green,neutre)
    b = RGBDifference(blue,neutre)
    
#----------- RGB correction calcul    
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    
#-----------  RGB correction with linear curve calcul (Bias)   
    dr1 = dr*strength_bias
    dg1 = dg*strength_bias
    db1 = db*strength_bias
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dr2 = dr-dr1
    dg2 = dg-dg1
    db2 = db-db1
    
#-----------  RGB correction with Rpow curve calcul        
    yr = (dr2 < 0) ? (1+dr2/100)*strength_rpow:(1+dr2/100)*strength_rpow 
    yg = (dg2 < 0) ? (1+dg2/100)*strength_rpow:(1+dg2/100)*strength_rpow 
    yb = (db2 < 0) ? (1+db2/100)*strength_rpow:(1+db2/100)*strength_rpow
    
#-----------  RGB correction with Spow curve calcul    
    sr = (dr2 < 0) ? (1+dr2/100)*strength_spow:(1+dr2/100)*strength_spow
    sg = (dg2 < 0) ? (1+dg2/100)*strength_spow:(1+dg2/100)*strength_spow
    sb = (db2 < 0) ? (1+db2/100)*strength_spow:(1+db2/100)*strength_spow
    sb = (db2 < 0) ? 1+db2/100:1+db2/100
                     
    RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = 1.0, R_RPow = yr, R_Spow = sr, R_SPMid = 0.5, R_Pord = false, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = 1.0, G_RPow = yg, G_Spow = sg, G_SPMid = 0.5, G_Pord = false,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = 1.0, B_RPow = yb, B_Spow = sb, B_SPMid = 0.5, B_Pord = false)
""")

return StackHorizontal(a,b,b1)
This script has three args for tune strength of bias, rpow and spow corrections.
Thanks
Nice sunday
Bernardd is offline   Reply With Quote
Old 26th May 2014, 19:54   #6  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hello StainlessS,

To day i have finished the automatic autowhite balance of RGBAdapt and i have written the automatic autowhite balance of CorlorYUV2. This two scripts below :

Code:
#AVISource("C:\..........\video.avi")
LoadPlugin("C:\..........\RGBAdapt_dll_v0.1-20140522\RGBAdapt.dll")

threshold = [<"threshold", 0, 255, 128>] # Middle ton for automatic white balance
strength_bias = [<"strength_bias", 0.1, 1.0, 0.5>] # Strength linear curve use
cont = [<"cont", 1.00, 1.50, 1.15>] # Contrast, necessary after linear curve
strength_Rpow = [<"Strength_Rpow", 0.0, 1.0, 0.5>]  # Strength Rpow curve use
strength_Spow = [<"Strength_Spow", 0.0, 1.0, 0.5>] # Strength Spow curve use
Spmid = [<"Spmid", 0.1, 0.99, 0.58>] # Middle point for Spow curve use
Pord_nb = [<"Pord_nb", 0, 1, 0>]
Pord = (Pord_nb == 0) ? false : true
show_info = [<"show_info", 0, 1, 0>]
comparison = [<"comparison", 0, 1, 0>]

original=last

ConvertToRGB32(matrix="Rec601")

neutre = BlankClip(last, pixel_type="RGB32", color=$000000)
red=ShowRed("RGB32")
green = ShowGreen("RGB32")
blue = ShowBlue("RGB32")

 ScriptClip(""" 

#------------ RGB values calcul
    r = RGBDifference(red,neutre)
    g = RGBDifference(green,neutre)
    b = RGBDifference(blue,neutre)
    
#----------- RGB correction calcul    
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    
#-----------  RGB correction with linear curve calcul (Bias)   
    dr1 = dr*strength_bias
    dg1 = dg*strength_bias
    db1 = db*strength_bias
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dr2 = dr-dr1
    dg2 = dg-dg1
    db2 = db-db1
    
#-----------  RGB correction with Rpow curve calcul        
    yr = (dr2 < 0) ? 1+(dr2*0.9/128)*strength_rpow: 1+(dr2*3/128)*strength_rpow 
    yg = (dg2 < 0) ? 1+(dg2*0.9/128)*strength_rpow: 1+(dg2*3/128)*strength_rpow 
    yb = (db2 < 0) ? 1+(db2*0.9/128)*strength_rpow: 1+(db2*3/128)*strength_rpow
    
    #~ yr = (dr2 < 0) ? (1+dr2/128)*strength_rpow:(1+dr2*Full_range)*strength_rpow 
    #~ yg = (dg2 < 0) ? (1+dg2/128)*strength_rpow:(1+dg2*Full_range)*strength_rpow 
    #~ yb = (db2 < 0) ? (1+db2/100)*strength_rpow:(1+db2*Full_range)*strength_rpow
    
#-----------  RGB correction with Spow curve calcul    
    sr = (dr2 < 0) ? 1+(dr2*0.9/128)*strength_spow: 1+(dr2*3/128)*strength_spow
    sg = (dg2 < 0) ? 1+(dg2*0.9/128)*strength_spow: 1+(dg2*3/128)*strength_spow
    sb = (db2 < 0) ? 1+(db2*0.9/128)*strength_spow: 1+(db2*3/128)*strength_spow
 
   (show_info == 0)? \                
    RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = cont, R_RPow = yr, R_Spow = sr, R_SPMid = Spmid, R_Pord = Pord, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = cont, G_RPow = yg, G_Spow = sg, G_SPMid = Spmid, G_Pord = Pord,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = cont, B_RPow = yb, B_Spow = sb, B_SPMid = Spmid, B_Pord = Pord):\
	 RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = cont, R_RPow = yr, R_Spow = sr, R_SPMid = Spmid, R_Pord = Pord, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = cont, G_RPow = yg, G_Spow = sg, G_SPMid = Spmid, G_Pord = Pord,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = cont, B_RPow = yb, B_Spow = sb, B_SPMid = Spmid, B_Pord = Pord)\
	.Subtitle("Red value :   "+String(r)+" Bias : "+String(dr1)+" Rpow : "+String(yr)+" Spow : "+String(sr),y=40)\
   .Subtitle("Green value : "+String(b)+" Bias : "+String(dg1)+" Rpow : "+String(yg)+" Spow : "+String(sg),y=60)\
    .Subtitle("Blue value :    "+String(b)+" Bias : "+String(db1)+" Rpow : "+String(yb)+" Spow : "+String(sb), y=80)
    	 
""")

ConvertToYV12(matrix="Rec601") 

(comparison == 0) ? last : StackHorizontal(original,last)
Code:
#AVISource("C:\............\video.avi")

LoadPlugin("C:\............\ColorYUV2_25_dll_20120529\ColorYUV2.dll")

threshold = [<"threshold", 0, 255, 127>] # Middle ton for automatic white balance
strength_bias = [<"strength_bias", 0.1, 1.0, 0.5>] # Strength linear curve use
cont = [<"cont", -20, 60, 51.1>]
strength_Rpow = [<"Strength_Rpow", 0.1, 1.0, 0.5>]  # Strength Rpow curve use
strength_Spow = [<"Strength_Spow", 0.1, 1.0, 0.5>] # Strength Spow curve use
Pord = [<"Pord_nb", 0, 1, 0>]
show_info = [<"show_info", 0, 1, 0>]
comparison = [<"comparison", 0, 1, 0>]

original=last

ScriptClip(""" 

#------------ YUV average value
    y = AverageLuma()
    u = AverageChromaU()
    v = AverageChromaV()
    
#----------- RGB correction calcul    
    dy = threshold - y
    du = threshold - u
    dv = threshold - v
    
#-----------  RGB correction with linear curve calcul (Bias)   
    dy1 = dy*strength_bias
    du1 = du*strength_bias
    dv1 = dv*strength_bias
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dy2 = dy-dy1
    du2 = du-du1
    dv2 = dv-dv1
    
#-----------  RGB correction with Rpow curve calcul       
    yy = dy2*strength_rpow
    yu = du2*strength_rpow 
    yv = dv2*strength_rpow
    
#-----------  RGB correction with Spow curve calcul
    sy = dy2*strength_spow
    su = du2*strength_spow
    sv = dv2*strength_spow

(show_info == 0)? \
     ColorYUV2(\
     off_y = dy1, cont_y = cont, rpow_y = yy, spow_y = sy, pord_y = pord,\
		off_u = du1, rpow_u = yu, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = yv, spow_v = sv, pord_v = pord):\
		ColorYUV2(\
     off_y = dy1, cont_y = cont, rpow_y = yy, spow_y = sy, pord_y = pord,\
		off_u = du1, rpow_u = yu, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = yv, spow_v = sv, pord_v = pord)\
     .Subtitle("Luma value : "+String(y)+" Bias : "+String(dy)+"  Rpow : "+String(yy)+" Spow : "+String(sy),y=40)\
      .Subtitle("U value : "+String(u)+"        Bias : "+String(du)+"  Rpow : "+String(yu)+" Spow : "+String(su),y=60)\
       .Subtitle("V value : "+String(v)+"       Bias : "+String(dv)+"  Rpow : "+String(yv)+" Spow : "+String(sv), y=80)
		
""")

(comparison == 0) ? last : StackHorizontal(original,last)
I believe these scripts can be used to make automatic white balance or at less to help, with their info displays to find best args values in manual script use.

Thanks for this script and also for the graffers, with them we know that we are doing.
Bernardd is offline   Reply With Quote
Old 26th May 2014, 20:02   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
Glad that your keeping busy
I'm busy myself at the moment, and dont have AVSPmod installed to try your scripts (I usually just use text editor and VDMod).
If you want to look for ideas, maybe try search for AWB by Martin53 (he has not been around for a good time, told me he was
on safari several months ago, hope those crocodiles did not get him).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 27th May 2014, 20:09   #8  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hello StainlessS,

I do believe that automatic white balance can not give back natural colors, but only nearest. There are for film external args which give bad white balance, like sunset for example. Thus my aim is to improve few, ColorYUV automatic functions. Because sometime i get cold colors.

With your graffer, i have understood that is because ColorYUV AutoWhite use only a bias correction with a linear curve. Thus i think your ColorYUV2 and RGBAdapt plugins should be more efficiency with rpow and spow curves. I think sunset light information is more readable in light tones, thus we do not must erase them in white balance action. Spow curve is good in this case.

My scripts are not all automatic. I need to keep args to choice and tune strength of linear, rpow and spow curves actions.

This scripts use only difference between 127 and each channel average value for automatic caculation. they are now operational, for ColorYUV2, i think is finished, for RGBAdapt i search still the best formula for Rpow and Spow inputs. In colorYUV2 these args input are linear, but in RGBAdapt, i smell a log input, but i have no found the good numbers.

In the next version, i shall write my script in function style.

I hope my search do not disturb you.

Thanks
Bernardd is offline   Reply With Quote
Old 27th May 2014, 21:55   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
I think that ColorYUV AutoWhite just centers U and V using Off_u and off_v (but cant remember how it decides, maybe by pixel population).

EDIT Scratch that, probably AverageChromaU, AverageChromaV, ie make them center at 128.

EDIT: Although I would suggest might be better only to do at most half way correction as above.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th May 2014 at 22:35.
StainlessS is offline   Reply With Quote
Old 29th May 2014, 00:28   #10  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hello StainlessS

Gavino have given me this autowhite coloryuv calculation in this post http://forum.doom9.org/showthread.ph...82#post1673682

But i think other formula is used for tune luma in autowhite. I do not find it, thus i have add contraste args in my two scripts.

Below the two scripts in function style version. In the end, after instruction " __End__", i have save the script to call the function with
AvsPmod Users Sliders.

Code:
function RGBAdapt_auto(clip clip, int "threshold", \
                                        float "strength_bias", float "cont", \
                                        float "strength_rpow", float "strength_spow", float "spmid",bool "pord",\
                                        bool "show_info", bool "comparison")

{

#----------------------------------------------based on  RGBADapt plugin ------------------------------------------#
#                 script autor  : StainlessS http://forum.doom9.org/showthread.php?p=1681286#post1681286           #
#------------------------------------------------------------------------------------------------------------------#
                                        
Assert(clip.IsRGB, "RGBAdapt-auto: source must be RGB")

global threshold = Default(threshold, 127)  # channel value range center for calculation 
global strength_bias = Default(strength_bias, 0.8) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
global cont = Default(cont, 1.2) # adjust luma contrast, default 1.2
global strength_rpow = Default(strength_rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
global strength_spow = Default(strength_spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0
global spmid = Default(spmid, 0.5) # Middle point for Spow curve use
global pord = Default(pord,false) # process Rpow curve before Spow curve or not (1), default 0
global show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false

global neutre = BlankClip( clip,pixel_type="RGB32", color=$000000)
global red=ShowRed(clip,"RGB32")
global green = ShowGreen(clip,"RGB32")
global blue = ShowBlue(clip,"RGB32")

 ScriptClip(clip, """

#------------ RGB values calcul
    r = RGBDifference(red,neutre) 
    g = RGBDifference(green,neutre) 
    b = RGBDifference(blue,neutre)  
    
#----------- RGB correction calcul    
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
    
#-----------  RGB correction with linear curve calcul (Bias)   
    dr1 = dr*strength_bias
    dg1 = dg*strength_bias
    db1 = db*strength_bias
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dr2 = dr-dr1
    dg2 = dg-dg1
    db2 = db-db1
    
#-----------  RGB correction with Rpow curve calcul        
    yr = exp((dr2/100)*strength_rpow)
    yg = exp((dg2/100)*strength_rpow)
    yb = exp((db2/100)*strength_rpow)
#-----------  RGB correction with Spow curve calcul    
    sr = exp((dr2/100)*strength_spow)
    sg = exp((dg2/100)*strength_spow)
    sb = exp((db2/100)*strength_spow)
 
   (show_info == false)? \
    RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = cont, R_RPow = yr, R_Spow = sr, R_SPMid = spmid, R_Pord = pord, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = cont, G_RPow = yg, G_Spow = sg, G_SPMid = spmid, G_Pord = pord,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = cont, B_RPow = yb, B_Spow = sb, B_SPMid = spmid, B_Pord = pord):\
	 RGBAdapt( \
    R_Bias = dr1, R_Gain = 1.0, R_Cont = cont, R_RPow = yr, R_Spow = sr, R_SPMid = spmid, R_Pord = pord, \
	 G_Bias = dg1, G_Gain = 1.0, G_Cont = cont, G_RPow = yg, G_Spow = sg, G_SPMid = spmid, G_Pord = pord,\
	 B_Bias = db1, B_Gain = 1.0, B_Cont = cont, B_RPow = yb, B_Spow = sb, B_SPMid = spmid, B_Pord = pord)\
	.Subtitle("Red value : "+String(r)+\
	          "\n     Middle - Red Value : "+String(dr)+\
	          "\n Bias : "+String(dr1)+\
	          "\n     Gamma and S correction base : "+String(dr2)+\
	          "\n Rpow : "+String(yr)+"            Spow : "+String(sr),y=40,lsp=20)\
   .Subtitle("Green value : "+String(b)+\
             "\n     Middle - Green Value : "+String(dg)+\     
             "\n Bias : "+String(dg1)+\
             "\n     Gamma and S correction base : "+String(dg2)+\
             "\n Rpow : "+String(yg)+"           Spow : "+String(sg),y=160,lsp=20)\
    .Subtitle("Blue value : "+String(b)+\
             "\n     Middle - Blue Value : "+String(db)+\
             "\n Bias : "+String(db1)+\
             "\n     Gamma and S correction base : "+String(db2)+\
             "\n Rpow : "+String(yb)+"             Spow : "+String(sb), y=280,lsp=20)
    	 
""")

(comparison == false) ? last : StackHorizontal(clip,last)

}

__End__

AVISource("C:\...............\video.avi")
LoadPlugin("C:\..........................\RGBAdapt_dll_v0.1-20140522\RGBAdapt.dll")
Import("C:\.............\RGBAdapt_auto.avsi")

threshold = [<"threshold", 0, 255, 127>] 
strength_bias = [<"strength_bias", 0.0, 1.0, 0.5>] 
cont = [<"cont", -3.0, 3.0, 1.2>]
strength_rpow = [<"Strength_rpow", 0.0, 4.0, 1.0>] 
strength_spow = [<"Strength_spow", 0.0, 4.0, 1.0>] 
spmid = [<"Spmid", 0.1, 0.99, 0.5>]
Pord_nb = [<"Pord", 0, 1, 1>]
pord = (Pord_nb == 0) ? false : true
show_info_nb = [<"show_info_nb", 0, 1, 0>]
show_info = (show_info_nb==0) ? false : true
comparison_nb = [<"comparison_nb", 0, 1, 0>]
comparison  = (comparison_nb==0) ? false : true

ConvertToRGB32(matrix="Rec601")

RGBAdapt_auto(threshold = threshold, \
                      strength_bias = strength_bias, cont = cont, \
                      strength_rpow =  strength_rpow, strength_spow = strength_spow, spmid = spmid, pord = pord,\
                      show_info = show_info, comparison = comparison)

ConvertToYV12(matrix="Rec601")
Code:
function ColorYUV2_auto(clip clip, \
                                        bool "process_luma", int "threshold", \
                                        float "strength_bias", float "cont", \
                                        float "strength_Rpow", float "strength_Spow", int "pord",\
                                        bool "show_info", bool "comparison")

{

#----------------------------------------------based on  ColorYUV2 plugin ------------------------------------------- #
#                 script autor  : StainlessS http://forum.doom9.org/showthread.php?p=1443313#post1443313              #
#--------------------------------------------------------------------------------------------------------------------#                                        
                                       
global process_luma = Default(process_luma, true)  # process or not the luma channel 
global threshold = Default(threshold, 127)  # channel value range center for calculation 
global strength_bias = Default(strength_bias, 0.5) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
global cont = Default(cont, 20.0) # adjust luma contrast, default 20.0
global strength_Rpow = Default(strength_Rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
global strength_Spow = Default(strength_Spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0
global pord = Default(pord,0) # process Rpow curve before Spow curve or not (1), default 0
global show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false
                                       
ScriptClip(clip, """ 

#------------ YUV average value
    y = AverageLuma()
    u = AverageChromaU()
    v = AverageChromaV()
    
#----------- RGB correction calcul    
    dy = (process_luma == true) ? threshold - y : 0
    du = threshold - u
    dv = threshold - v
    
#-----------  RGB correction with linear curve calcul (Bias)   
    dy1 = dy*strength_bias
    du1 = du*strength_bias
    dv1 = dv*strength_bias
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dy2 = dy-dy1
    du2 = du-du1
    dv2 = dv-dv1
    
#-----------  RGB correction with Rpow curve calcul       
    yy = dy2*strength_rpow
    yu = du2*strength_rpow 
    yv = dv2*strength_rpow
    
#-----------  RGB correction with Spow curve calcul
    sy = dy2*strength_spow
    su = du2*strength_spow
    sv = dv2*strength_spow

(show_info == false)? \
     ColorYUV2(\
     off_y = dy1, cont_y = cont, rpow_y = yy, spow_y = sy, pord_y = pord,\
		off_u = du1, rpow_u = yu, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = yv, spow_v = sv, pord_v = pord):\
		ColorYUV2(\
     off_y = dy1, cont_y = cont, rpow_y = yy, spow_y = sy, pord_y = pord,\
		off_u = du1, rpow_u = yu, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = yv, spow_v = sv, pord_v = pord)\
     .Subtitle("Luma value : "+String(y)+\
               "\n     Middle - Luma value : "+String(dy)+\
               "\n Bias : "+String(dy1)+\
               "\n     Gamma and S correction base : "+String(dy2)+\
               "\n Rpow : "+String(yy)+"         Spow : "+String(sy),y=40,lsp=20)\
     .Subtitle("U Chroma value : "+String(u)+\
               "\n     Middle - U Chroma value : "+String(du)+\
               "\n Bias : "+String(du1)+\
               "\n     Gamma and S correction base : "+String(du2)+\
               "\n Rpow : "+String(yu)+"         Spow : "+String(su),y=160,lsp=20)\
      .Subtitle("V value : "+String(v)+\
               "\n     Middle - V Chroma value : "+String(dv)+\
               "\n Bias : "+String(dv1)+\
               "\n     Gamma and S correction base : "+String(dv2)+\
               "\n  Rpow : "+String(yv)+"          Spow : "+String(sv),y=280,lsp=20)
		
""")

( comparison == false) ? last : StackHorizontal(clip,last)

}

__End__

AVISource("C:\..................\video.avi")
LoadPlugin("C:\..................\ColorYUV2_25_dll_20120529\ColorYUV2.dll")
Import("C:\...............\ColorYUV2 auto.avsi")

process_luma_nb = [<"process_luma_nb", 0, 1, 1>]
process_luma = (process_luma_nb==0) ? false : true
threshold = [<"threshold", 0, 255, 127>] 
strength_bias = [<"strength_bias", 0.0, 1.0, 0.5>] 
cont = [<"cont", -20, 60, 20.0>]
strength_Rpow = [<"Strength_Rpow", 0.0, 4.0, 0.0>] 
strength_Spow = [<"Strength_Spow", 0.0, 4.0, 1.0>] 
Pord = [<"Pord", 0, 1, 0>]
show_info_nb = [<"show_info_nb", 0, 1, 0>]
show_info = (show_info_nb==0) ? false : true
comparison_nb = [<"comparison_nb", 0, 1, 0>]
comparison  = (comparison_nb==0) ? false : true
                      
ColorYUV2_auto(last,process_luma=process_luma, threshold=threshold, \
                       strength_bias=strength_bias,cont=cont, \
                       strength_Rpow = strength_Rpow, strength_Spow=strength_Spow, pord=pord,\
                       show_info=show_info, comparison=comparison)
The smart ScripClip use has given to me by Gavino.
Thanks

Last edited by Bernardd; 29th May 2014 at 00:34.
Bernardd is offline   Reply With Quote
Old 29th May 2014, 01:10   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
AutoWhite only adjust chroma U and V, (to 127 as Gavino said, I mistakenly said 128), luma is not touched by it.
AutoGain modifies the Luma Channel.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 2nd June 2014, 19:46   #12  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hi !

I have observed your ColorYUV2 source and i have written an autogain tunable function.
The new script version is there :
Code:
function ColorYUV2_auto(clip clip, int "threshold", float "strength_bias",float "strength_Rpow", float "strength_Spow", int "pord",\                 
                                        bool "autogain", float "luma_threshold",\
                                        bool "show_info", bool "comparison")

{

#----------------------------------------------based on  ColorYUV2 plugin ---------------------------------------------------------------------#
#                 script autor  : StainlessS http://forum.doom9.org/showthread.php?p=1443313#post1443313                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #                                        
                                       

global threshold = Default(threshold, 127)  # channel value range center for calculation 
global strength_bias = Default(strength_bias, 0.8) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
global strength_Rpow = Default(strength_Rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
global strength_Spow = Default(strength_Spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0
global pord = Default(pord,1) # process Rpow curve before Spow curve or not (1), default 0
global autogain = Default(autogain, false)
global luma_threshold = Default(luma_threshold, 0.35)  # channel value range center for calculation
global show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false
                                       
ScriptClip(clip, """ 

#-------------------------------------------- 
#               Autowhite process
#-------------------------------------------- 
 
#------------ UV average values
    u = AverageChromaU()
    v = AverageChromaV()
    
#----------- UV corrections calculation       
    du = threshold - u
    dv = threshold - v
    
#-----------  UV corrections with linear curve calculation (Offset)       
    du1 = du*strength_bias
    dv1 = dv*strength_bias
    
#-----------  UV corrections range with Rpow and Spow curves calculation    
    du2 = du-du1
    dv2 = dv-dv1
    
#-----------  UV corrections with Rpow curve calculation       
    ru = du2*strength_rpow 
    rv = dv2*strength_rpow
    
#-----------  UV corrections with Spow curve calculation
    su = du2*strength_spow
    sv = dv2*strength_spow
    
#-------------------------------------------- 
#               Autogain process
#--------------------------------------------    
    
#------------ Y max and min values
        
    y_max_value = float(YPlaneMax(threshold = luma_threshold))
    y_max = min (y_max_value, 236)
    y_min_value = float(YPlaneMin(threshold = luma_threshold))
    y_min = max (16, y_min_value)
    
#-----------  Y gain correction calculation    
    
    f = (autogain == true) ?  float(220/(y_max - y_min)) : 1
    gy = 256*f-256
    
#-----------  Y offset correction calculation    
    new_y_max = y_max * f # only for display
    new_y_min = y_min * f
    dy = (autogain == true) ? 16 - new_y_min : 0  
    
(show_info == false) ? \
     ColorYUV2(\
     gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\
		 :\
		ColorYUV2(\
		gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\		
     .Subtitle(" U Chroma value : "+String(u)+"\n"+\
               "     Middle - U Chroma value : "+String(du)+"\n"+\
               " Bias : "+String(du1)+"\n"+\
               "     Gamma and S correction base : "+String(du2)+"\n"+\
               " Rpow : "+String(ru)+"         Spow : "+String(su),y=40,lsp=20)\
      .Subtitle(" V value : "+String(v)+"\n"+\
               "     Middle - V Chroma value : "+String(dv)+"\n"+\
               " Bias : "+String(dv1)+"\n"+\
               "     Gamma and S correction base : "+String(dv2)+"\n"+\
               " Rpow : "+String(rv)+"          Spow : "+String(sv),y=160,lsp=20)\
      .Subtitle(" Y max : "+String(y_max)+"           Y min : "+String(y_min)+"        Luma_Threshold : "+String(luma_threshold)+"\n"+\
                "    Y factor : "+String(f)+"         Y gain : "+String(gy)+"         Y offset : "+String(dy)+"\n"+\
                " New Y max : "+String(new_y_max + dy)+"  New Y min : "+String(new_y_min + dy),y=280,lsp=20)
		
""")

( comparison == false) ? last : StackHorizontal(clip,last)

}

__End__
# Below, call script with AvsPmod user sliders

AVISource("C:\......................\video.avi")

LoadPlugin("C:\...................\ColorYUV2_25_dll_20120529\ColorYUV2.dll")
Import("C:\.................\ColorYUV2 auto.avs")

[<separator = "AWB tunning args">] 
[<separator = "No AWB is strength_bias = strength_rpow = strength_spow = 0">]
threshold = [<"threshold", 0, 255, 127>] 
strength_bias = [<"strength_bias", 0.0, 1.0, 0.8>] 
strength_Rpow = [<"strength_Rpow", 0.0, 4.0, 1.0>] 
strength_Spow = [<"strength_Spow", 0.0, 4.0, 1.0>] 
Pord = [<"Pord", 0, 1, 1>]

[<separator = "Autogain tunning args">]
autogain_nb = [<"autogain_nb", 0, 1, 0>]
luma_threshold = [<"Luma_threshold", 0.00, 1.00, 0.35>]
autogain = (autogain_nb == 0) ? false : true

[<separator = "Output choice">]
show_info_nb = [<"show_info_nb", 0, 1, 0>]
show_info = (show_info_nb==0) ? false : true
comparison_nb = [<"comparison_nb", 0, 1, 0>]
comparison  = (comparison_nb==0) ? false : true
                      
ColorYUV2_auto(last, threshold=threshold, strength_bias=strength_bias, strength_Rpow = \
                       strength_Rpow, strength_Spow=strength_Spow, pord=pord,\
                       autogain = autogain, Luma_threshold = luma_threshold,\
                       show_info=show_info, comparison=comparison)
The tunning args is the Avisynth internal runtime function threshold (YPlaneMax and YPlaneMin).
When autogain is too strong with overbound light i can now decrease threshold for best result.

But i have two questions.

first
Do you know if in basic autogain coloryuv function, is it a threshold for selected luma (threshold nearest 0.3) ?

secund
In my script i must define variables like global to enable their use in ScriptClip. Thus whit short script like this, only the args
for the second call function is use.

a=ColorYUV2_auto(show_info=true)
b=ColorYUV2_auto(show_info=false)
StackHorizontal(a,b)

Have you a tips ?
Bernardd is offline   Reply With Quote
Old 2nd June 2014, 23:54   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,379
Quote:
Originally Posted by Bernardd View Post
In my script i must define variables like global to enable their use in ScriptClip. Thus whit short script like this, only the args for the second call function is use.
The GRunT plugin is designed to solve this problem (and others).
It replaces the built-in run-time filters (ScriptClip, etc) with extended versions that have a couple of extra arguments, providing (among other things) a simple, natural and robust way to pass local variables into a run-time script from 'outside'.

For more details, see the description of the args parameter in the GRunT thread (and the supplied doc), which should hopefully tell you all you need to know.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 3rd June 2014, 15:41   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
As Gavino says above, use Grunt for args, much nicer than standard Scriptclip.

Should this not be 235(as per rec601 Luma max)
Code:
y_max = min (y_max_value, 236)

Not sure about this line [Should 220 be 219 (235-16)]
Code:
f = (autogain == true) ?  float(220/(y_max - y_min)) : 1
Maybe should be
Code:
f = (autogain == true) ?  219.0/(y_max - y_min) : 1.0
Dont like your mixed use of Int and Float, there seem to be a number of places in your script where
you will sometimes have Int and Sometimes float, with unexpected consequences.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 3rd June 2014, 22:06   #15  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
StainlessS, Gavino,
Thousand thanks, your plugins are great.

I have written my script one more once.

For ColorYUV2, i think auto white balance and autogain have a sense. With rpow and spow args, the result is less flat than a coloryuv use.
I can keep the sunset light.

Code:
function ColorYUV2_auto(clip clip, int "threshold", float "strength_bias",float "strength_Rpow", float "strength_Spow", int "pord",\                 
                                        bool "autogain", float "luma_threshold",\
                                        bool "show_info", bool "comparison")

{

#----------------------------------------------based on  ColorYUV2 plugin ---------------------------------------------------------------------#
#                 script autor  : StainlessS http://forum.doom9.org/showthread.php?p=1443313#post1443313                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #                                        

#---------------------------------------------- need  GRunT plugin ----------------------------------------------------------------------------#
#                 script autor  : Gavino http://forum.doom9.org/showthread.php?p=1157083#post1157083                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #
                                       

threshold = Default(threshold, 127)  # channel value range center for calculation 
strength_bias = Default(strength_bias, 0.8) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
strength_Rpow = Default(strength_Rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
strength_Spow = Default(strength_Spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0
pord = Default(pord,1) # process Rpow curve before Spow curve or not (1), default 0
autogain = Default(autogain, false)
luma_threshold = Default(luma_threshold, 0.35)  # channel value range center for calculation
show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false
                                       
ScriptClip(clip, """ 

#-------------------------------------------- 
#               Autowhite process
#-------------------------------------------- 
 
#------------ UV average values
    u = AverageChromaU()
    v = AverageChromaV()
    
#----------- UV corrections calculation       
    du = threshold - u
    dv = threshold - v
    
#-----------  UV corrections with linear curve calculation (Offset)       
    du1 = du*strength_bias
    dv1 = dv*strength_bias
    
#-----------  UV corrections range with Rpow and Spow curves calculation    
    du2 = du-du1
    dv2 = dv-dv1
    
#-----------  UV corrections with Rpow curve calculation       
    ru = du2*strength_rpow 
    rv = dv2*strength_rpow
    
#-----------  UV corrections with Spow curve calculation
    su = du2*strength_spow
    sv = dv2*strength_spow
    
#-------------------------------------------- 
#               Autogain process
#--------------------------------------------    
    
#------------ Y max and min values
        
    y_max_value = float(YPlaneMax(threshold = luma_threshold))
    y_max = min (y_max_value, 235.0)
    y_min_value = float(YPlaneMin(threshold = luma_threshold))
    y_min = max (16.0, y_min_value)
    
#-----------  Y gain correction calculation    
    
    f = (autogain == true) ?  float(219.0/(y_max - y_min)) : 1.0
    gy = 256.0*f-256.0
    
#-----------  Y offset correction calculation    
    new_y_max = y_max * f # only for display
    new_y_min = y_min * f
    dy = (autogain == true) ? 16.0 - new_y_min : 0.0  
    
(show_info == false) ? \
     ColorYUV2(\
     gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\
		 :\
		ColorYUV2(\
		gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\		
     .Subtitle(" U Chroma value : "+String(u)+"\n"+\
               "     Middle - U Chroma value : "+String(du)+"\n"+\
               " Bias : "+String(du1)+"\n"+\
               "     Gamma and S correction base : "+String(du2)+"\n"+\
               " Rpow : "+String(ru)+"         Spow : "+String(su),y=40,lsp=20)\
      .Subtitle(" V value : "+String(v)+"\n"+\
               "     Middle - V Chroma value : "+String(dv)+"\n"+\
               " Bias : "+String(dv1)+"\n"+\
               "     Gamma and S correction base : "+String(dv2)+"\n"+\
               " Rpow : "+String(rv)+"          Spow : "+String(sv),y=160,lsp=20)\
      .Subtitle(" Y max : "+String(y_max)+"           Y min : "+String(y_min)+"        Luma_Threshold : "+String(luma_threshold)+"\n"+\
                "    Y factor : "+String(f)+"         Y gain : "+String(gy)+"         Y offset : "+String(dy)+"\n"+\
                " New Y max : "+String(new_y_max + dy)+"  New Y min : "+String(new_y_min + dy),y=280,lsp=20)
		
""", args = "threshold, strength_bias, strength_rpow, strength_spow, pord, autogain, luma_threshold, show_info")

( comparison == false) ? last : StackHorizontal(clip,last)

}
For RGBAdapt, i think auto white balance has no sense, because apply rule 127 - channel value to find the white is forgetting that in each channel value
is a part for luma datas. I have not found ideas to separate efficiently luma and chroma before apply auto white balance. But like this rule give some results
with a good look, i have converted my script in help script for manual white balance. The script propose a white balance start for manual search.

Code:
function RGBAdapt_half_auto(clip clip, \
             float "R_bias_manu", float "R_gain", float "R_cont", float "R_rpow_manu", float "R_spow_manu", float "R_spmid", bool "R_pord",\
             float "G_bias_manu", float "G_gain", float "G_cont", float "G_rpow_manu", float "G_spow_manu", float "G_spmid", bool "G_pord",\
             float "B_bias_manu", float "B_gain", float "B_cont", float "B_rpow_manu", float "B_spow_manu", float "B_spmid", bool "B_pord",\
             int "threshold", float "strength_bias", float "strength_rpow", float "strength_spow",\
             bool "show_info", bool "comparison")

{

#----------------------------------------------based on  RGBADapt plugin ---------------------------------------------------------------------#
#                 script autor  : StainlessS http://forum.doom9.org/showthread.php?p=1681286#post1681286                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #

#---------------------------------------------- need  GRunT plugin ----------------------------------------------------------------------------#
#                 script autor  : Gavino http://forum.doom9.org/showthread.php?p=1157083#post1157083                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #
                                        
Assert(clip.IsRGB, "RGBAdapt-auto: source must be RGB")

R_bias_manu = Default(R_bias_manu, 0)  # same range with original R_bias args 
G_bias_manu = Default(G_bias_manu, 0)  # same range with original G_bias args
B_bias_manu = Default(B_bias_manu, 0)  # same range with original B_bias args

R_gain = Default(R_gain, 1)  # It is original R_gain args, range -8 to 8 center 1.0
G_gain = Default(G_gain, 1)  # It is original G_gain args, range -8 to 8 center 1.0
B_gain = Default(B_gain, 1)  # It is original B_gain args, range -8 to 8 center 1.0

R_cont = Default(R_cont, 1)  # It is original R_cont args, range -8 to 8 center 1.0
G_cont = Default(G_cont, 1)  # It is original G_cont args, range -8 to 8 center 1.0
B_cont = Default(B_cont, 1)  # It is original B_cont args, range -8 to 8 center 1.0

R_rpow_manu = Default(R_rpow_manu, 0)  # range -0.8 to 3.0 center 0 (original R_rpow range 0.1 to 4.0 center 1.0)
G_rpow_manu = Default(G_rpow_manu, 0)  # range -0.8 to 3.0 center 0 (original G_rpow range 0.1 to 4.0 center 1.0)
B_rpow_manu = Default(B_rpow_manu, 0)  # range -0.8 to 3.0 center 0 (original B_rpow range 0.1 to 4.0 center 1.0)

R_spow_manu = Default(R_spow_manu, 0)  # range -0.8 to 3.0 center 0 (original R_spow range 0.1 to 4.0 center 1.0)
G_spow_manu = Default(G_spow_manu, 0)  # range -0.8 to 3.0 center 0 (original G_spow range 0.1 to 4.0 center 1.0)
B_spow_manu = Default(B_spow_manu, 0)  # range -0.8 to 3.0 center 0 (original B_spow range 0.1 to 4.0 center 1.0)

R_spmid = Default(R_spmid, 0.5)  # It is original R_spmid args, range 0.1 to 0.99 center 0.5
G_spmid = Default(G_spmid, 0.5)  # It is original G_spmid args, range 0.1 to 0.99 center 0.5
B_spmid = Default(B_spmid, 0.5)  # It is original B_spmid args, range 0.1 to 0.99 center 0.5

R_pord = Default(R_pord, false)  # It is original R_pord args
G_pord = Default(G_pord, false)  # It is original G_pord args
B_pord = Default(B_pord, false)  # It is original B_pord args

threshold = Default(threshold, 127)  # channel value range center for calculation 
strength_bias = Default(strength_bias, 0.8) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
strength_rpow = Default(strength_rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
strength_spow = Default(strength_spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0

show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false

neutre = BlankClip( clip,pixel_type="RGB32", color=$000000)
red=ShowRed(clip,"RGB32")
green = ShowGreen(clip,"RGB32")
blue = ShowBlue(clip,"RGB32")

 ScriptClip(clip, """

#------------ RGB values calcul
    r = RGBDifference(red,neutre) 
    g = RGBDifference(green,neutre) 
    b = RGBDifference(blue,neutre)  
    
#----------- RGB correction calcul    
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
   
#-----------  RGB correction with linear curve calcul (Bias)   
    dr1 = dr*strength_bias + R_bias_manu
    dg1 = dg*strength_bias + G_bias_manu
    db1 = db*strength_bias + G_bias_manu
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dr2 = dr-dr1
    dg2 = dg-dg1
    db2 = db-db1
    
#-----------  RGB correction with Rpow curve calcul        
    yr = exp((dr2/100)*strength_rpow) + R_Rpow_manu
    yg = exp((dg2/100)*strength_rpow) + G_Rpow_manu
    yb = exp((db2/100)*strength_rpow) + B_Rpow_manu
    
#-----------  RGB correction with Spow curve calcul    
    sr = exp((dr2/100)*strength_spow)  + R_spow_manu
    sg = exp((dg2/100)*strength_spow)  + G_spow_manu
    sb = exp((db2/100)*strength_spow)  + B_spow_manu
       
   (show_info == false)? \
    RGBAdapt( \
    R_Bias = dr1, R_Gain = R_gain, R_Cont = R_cont, R_RPow = yr, R_Spow = sr, R_SPMid = R_spmid, R_Pord = R_pord, \
	 G_Bias = dg1, G_Gain = G_gain, G_Cont = G_cont, G_RPow = yg, G_Spow = sg, G_SPMid = G_spmid, G_Pord = G_pord,\
	 B_Bias = db1, B_Gain = B_gain, B_Cont = B_cont, B_RPow = yb, B_Spow = sb, B_SPMid = B_spmid, B_Pord = B_pord):\
	 RGBAdapt( \
    R_Bias = dr1, R_Gain = R_gain, R_Cont = R_cont, R_RPow = yr, R_Spow = sr, R_SPMid = R_spmid, R_Pord = R_pord, \
	 G_Bias = dg1, G_Gain = G_gain, G_Cont = G_cont, G_RPow = yg, G_Spow = sg, G_SPMid = G_spmid, G_Pord = G_pord,\
	 B_Bias = db1, B_Gain = B_gain, B_Cont = B_cont, B_RPow = yb, B_Spow = sb, B_SPMid = B_spmid, B_Pord = B_pord)\
	.Subtitle("Red value : "+String(r)+\
	          "\n     Middle - Red Value : "+String(dr)+\
	          "\n Bias : "+String(dr1)+\
	          "\n     Gamma and S correction base : "+String(dr2)+\
	          "\n Rpow : "+String(yr)+"            Spow : "+String(sr),y=40,lsp=20)\
   .Subtitle("Green value : "+String(g)+\
             "\n     Middle - Green Value : "+String(dg)+\     
             "\n Bias : "+String(dg1)+\
             "\n     Gamma and S correction base : "+String(dg2)+\
             "\n Rpow : "+String(yg)+"           Spow : "+String(sg),y=160,lsp=20)\
    .Subtitle("Blue value : "+String(b)+\
             "\n     Middle - Blue Value : "+String(db)+\
             "\n Bias : "+String(db1)+\
             "\n     Gamma and S correction base : "+String(db2)+\
             "\n Rpow : "+String(yb)+"             Spow : "+String(sb), y=280,lsp=20)
    	 
""", args = "R_bias_manu, R_gain, R_cont, R_rpow_manu, R_spow_manu, R_spmid, R_pord," +\
                   "G_bias_manu, G_gain, G_cont, G_rpow_manu, G_spow_manu, G_spmid, G_pord,"+\
                   "B_bias_manu, B_gain, B_cont, B_rpow_manu, B_spow_manu, B_spmid, B_pord,"+\
                   "neutre, red, green, blue,"+\
                   "threshold, strength_bias, strength_rpow, strength_spow, show_info")


(comparison == false) ? last : StackHorizontal(clip,last)

}
Thanks to have spend your time to answer me.
Bernardd is offline   Reply With Quote
Old 3rd June 2014, 22:26   #16  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
For RGB, I suggest take a peek at VirtualDub plugin 'White Balance' source by Jim Leonard,
I think I examined this about 8 maybe 10 years ago, think it got the highest frame pixel value of R, G and B,
and made them the same (adding difference to all pixels of adjusted channels),
and then did 'Top relative contrast' on the channels that had to be changed.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 3rd June 2014 at 22:33.
StainlessS is offline   Reply With Quote
Old 4th June 2014, 23:24   #17  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hello StainlessS,

I cannot apply your proposal because i do not get the highest frame pixel value. Avisynth runtime function give only RGB difference.
It is the limit of my process. I think that my RGBAdapt_half_auto script (last version below) is a lab script, a little help for manual
white balance search.

Code:
function RGBAdapt_half_auto(clip clip, bool "same",\
             float "R_gain", float "R_cont", float "R_spmid", bool "R_pord",\
             float "G_gain", float "G_cont", float "G_spmid", bool "G_pord",\
             float "B_gain", float "B_cont", float "B_spmid", bool "B_pord",\
             float "Gain", float "Cont", float "Spmid", bool "Pord",\
             int "threshold", float "strength_bias", float "strength_rpow", float "strength_spow",\
             bool "show_info", bool "comparison")

{

#----------------------------------------------based on  RGBADapt plugin ---------------------------------------------------------------------#
#                 script autor  : StainlessS http://forum.doom9.org/showthread.php?p=1681286#post1681286                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #

#---------------------------------------------- need  GRunT plugin ----------------------------------------------------------------------------#
#                 script autor  : Gavino http://forum.doom9.org/showthread.php?p=1157083#post1157083                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #
                                        
Assert(clip.IsRGB, "RGBAdapt-auto: source must be RGB")

same = Default(same,false) # same correction in the three channels

R_gain = Default(R_gain, 1)  # It is original R_gain args, range -8 to 8 center 1.0
G_gain = Default(G_gain, 1)  # It is original G_gain args, range -8 to 8 center 1.0
B_gain = Default(B_gain, 1)  # It is original B_gain args, range -8 to 8 center 1.0
Gain = Default(Gain, 0)  # same range with original gain args
R_Gain = (same == false) ? R_Gain : Gain
G_Gain = (same == false) ? G_Gain : Gain
B_Gain = (same == false) ? B_Gain : Gain

R_cont = Default(R_cont, 1)  # It is original R_cont args, range -8 to 8 center 1.0
G_cont = Default(G_cont, 1)  # It is original G_cont args, range -8 to 8 center 1.0
B_cont = Default(B_cont, 1)  # It is original B_cont args, range -8 to 8 center 1.0
Cont = Default(Cont, 0)  # same range with original cont args
R_Cont = (same == false) ? R_Cont : Cont
G_Cont = (same == false) ? G_Cont : Cont
B_Cont = (same == false) ? B_Cont : Cont

R_spmid = Default(R_spmid, 0.5)  # It is original R_spmid args, range 0.1 to 0.99 center 0.5
G_spmid = Default(G_spmid, 0.5)  # It is original G_spmid args, range 0.1 to 0.99 center 0.5
B_spmid = Default(B_spmid, 0.5)  # It is original B_spmid args, range 0.1 to 0.99 center 0.5
Spmid = Default(Spmid, 0)  # same range with original Spmid args
R_spmid = (same == false) ? R_spmid : Spmid
G_spmid = (same == false) ? G_spmid : Spmid
B_spmid = (same == false) ? B_spmid : Spmid

R_pord = Default(R_pord, false)  # It is original R_pord args
G_pord = Default(G_pord, false)  # It is original G_pord args
B_pord = Default(B_pord, false)  # It is original B_pord args
Pord = Default(Pord, 0)  # same range with original Pord args
R_pord = (same == false) ? R_pord : Pord
G_pord = (same == false) ? G_pord : Pord
B_pord = (same == false) ? B_pord : Pord

threshold = Default(threshold, 127)  # channel value range center for calculation 
strength_bias = Default(strength_bias, 0.8) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
strength_rpow = Default(strength_rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
strength_spow = Default(strength_spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0

show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false

neutre = BlankClip( clip,pixel_type="RGB32", color=$000000)
red=ShowRed(clip,"RGB32")
green = ShowGreen(clip,"RGB32")
blue = ShowBlue(clip,"RGB32")

 ScriptClip(clip, """

#------------ RGB values calcul
    r = RGBDifference(red,neutre) 
    g = RGBDifference(green,neutre) 
    b = RGBDifference(blue,neutre)  
    
#----------- RGB correction calcul    
    dr = threshold - r
    dg = threshold - g
    db = threshold - b
   
#-----------  RGB correction with linear curve calcul (Bias)   
    dr1 = dr*strength_bias
    dg1 = dg*strength_bias
    db1 = db*strength_bias
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dr2 = dr-dr1
    dg2 = dg-dg1
    db2 = db-db1
    
#-----------  RGB correction with Rpow curve calcul        
    yr = exp((dr2/100)*strength_rpow)
    yg = exp((dg2/100)*strength_rpow)
    yb = exp((db2/100)*strength_rpow)
    
#-----------  RGB correction with Spow curve calcul    
    sr = exp((dr2/100)*strength_spow)
    sg = exp((dg2/100)*strength_spow)
    sb = exp((db2/100)*strength_spow)
       
   (show_info == false)? \
    RGBAdapt( \
    R_Bias = dr1, R_Gain = R_gain, R_Cont = R_cont, R_RPow = yr, R_Spow = sr, R_SPMid = R_spmid, R_Pord = R_pord, \
	 G_Bias = dg1, G_Gain = G_gain, G_Cont = G_cont, G_RPow = yg, G_Spow = sg, G_SPMid = G_spmid, G_Pord = G_pord,\
	 B_Bias = db1, B_Gain = B_gain, B_Cont = B_cont, B_RPow = yb, B_Spow = sb, B_SPMid = B_spmid, B_Pord = B_pord):\
	 RGBAdapt( \
    R_Bias = dr1, R_Gain = R_gain, R_Cont = R_cont, R_RPow = yr, R_Spow = sr, R_SPMid = R_spmid, R_Pord = R_pord, \
	 G_Bias = dg1, G_Gain = G_gain, G_Cont = G_cont, G_RPow = yg, G_Spow = sg, G_SPMid = G_spmid, G_Pord = G_pord,\
	 B_Bias = db1, B_Gain = B_gain, B_Cont = B_cont, B_RPow = yb, B_Spow = sb, B_SPMid = B_spmid, B_Pord = B_pord)\
	.Subtitle("Red value : "+String(r)+\
	          "\n     Middle - Red Value : "+String(dr)+\
	          "\n Bias : "+String(dr1)+\
	          "\n     Gamma and S correction base : "+String(dr2)+\
	          "\n Rpow : "+String(yr)+"            Spow : "+String(sr),y=40,lsp=20)\
   .Subtitle("Green value : "+String(g)+\
             "\n     Middle - Green Value : "+String(dg)+\     
             "\n Bias : "+String(dg1)+\
             "\n     Gamma and S correction base : "+String(dg2)+\
             "\n Rpow : "+String(yg)+"           Spow : "+String(sg),y=160,lsp=20)\
    .Subtitle("Blue value : "+String(b)+\
             "\n     Middle - Blue Value : "+String(db)+\
             "\n Bias : "+String(db1)+\
             "\n     Gamma and S correction base : "+String(db2)+\
             "\n Rpow : "+String(yb)+"             Spow : "+String(sb), y=280,lsp=20)
    	 
""", args = "R_gain, R_cont,R_spmid, R_pord," +\
                   "G_gain, G_cont, G_spmid, G_pord,"+\
                   "B_gain, B_cont, B_spmid, B_pord,"+\
                   "Gain, Cont, Spmid, Pord, same,"+\
                   "neutre, red, green, blue,"+\
                   "threshold, strength_bias, strength_rpow, strength_spow, show_info")


(comparison == false) ? last : StackHorizontal(clip,last)

}
ColorYUV2_auto is full ops, no many args, only one dangerous args : luma_threshold which is sometime cause of bright flicker when it
is too weak.

Code:
function ColorYUV2_auto(clip clip, float "strength_bias",float "strength_Rpow", float "strength_Spow", int "pord",\                 
                                        bool "autogain", float "luma_threshold", bool "show_info", bool "comparison")

{

#----------------------------------------------based on  ColorYUV2 plugin ---------------------------------------------------------------------#
#                 script autor  : StainlessS http://forum.doom9.org/showthread.php?p=1443313#post1443313                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #                                        

#---------------------------------------------- need  GRunT plugin ----------------------------------------------------------------------------#
#                 script autor  : Gavino http://forum.doom9.org/showthread.php?p=1157083#post1157083                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #
                                       

strength_bias = Default(strength_bias, 0.5) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
strength_Rpow = Default(strength_Rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
strength_Spow = Default(strength_Spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0
pord = Default(pord,1) # process Rpow curve before Spow curve or not (1), default 0
autogain = Default(autogain, false)
luma_threshold = Default(luma_threshold, 0.50)  # selected luma value percentage for calculation, too weak can be cause of light flicker
show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false
                                       
ScriptClip(clip, """ 

#-------------------------------------------- 
#               Autowhite process
#-------------------------------------------- 
 
#------------ UV average values
    u = AverageChromaU()
    v = AverageChromaV()
    
#----------- UV corrections calculation       
    du = 127.0 - u
    dv = 127.0 - v
    
#-----------  UV corrections with linear curve calculation (Offset)       
    du1 = du*strength_bias
    dv1 = dv*strength_bias
    
#-----------  UV corrections range with Rpow and Spow curves calculation    
    du2 = du-du1
    dv2 = dv-dv1
    
#-----------  UV corrections with Rpow curve calculation       
    ru = du2*strength_rpow 
    rv = dv2*strength_rpow
    
#-----------  UV corrections with Spow curve calculation
    su = du2*strength_spow
    sv = dv2*strength_spow
    
#-------------------------------------------- 
#               autogain process
#--------------------------------------------    
    
#------------ Y max and min values
        
    y_max_value = float(YPlaneMax(threshold = luma_threshold))
    y_max = min (y_max_value, 235.0)
    y_min_value = float(YPlaneMin(threshold = luma_threshold))
    y_min = max (16.0, y_min_value)
    
#-----------  Y gain correction calculation    
    
    f = (autogain == true) ?  float(219.0/(y_max - y_min)) : 1.0
    gy = 256.0*f-256.0
    
#-----------  Y offset correction calculation    
    new_y_max = y_max * f # only for display
    new_y_min = y_min * f
    dy = (autogain == true) ? 16.0 - new_y_min : 0.0  
    
(show_info == false) ? \
     ColorYUV2(\
     gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\
		 :\
		ColorYUV2(\
		gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\		
     .Subtitle(" U Chroma value : "+String(u)+"\n"+\
               "     Middle - U Chroma value : "+String(du)+"\n"+\
               " Bias : "+String(du1)+"\n"+\
               "     Gamma and S correction base : "+String(du2)+"\n"+\
               " Rpow : "+String(ru)+"         Spow : "+String(su),y=40,lsp=20)\
      .Subtitle(" V value : "+String(v)+"\n"+\
               "     Middle - V Chroma value : "+String(dv)+"\n"+\
               " Bias : "+String(dv1)+"\n"+\
               "     Gamma and S correction base : "+String(dv2)+"\n"+\
               " Rpow : "+String(rv)+"          Spow : "+String(sv),y=160,lsp=20)\
      .Subtitle(" Y max : "+String(y_max)+"           Y min : "+String(y_min)+"        Luma_Threshold : "+String(luma_threshold)+"\n"+\
                "    Y factor : "+String(f)+"         Y gain : "+String(gy)+"         Y offset : "+String(dy)+"\n"+\
                " New Y max : "+String(new_y_max + dy)+"  New Y min : "+String(new_y_min + dy),y=280,lsp=20)
		
""", args = "strength_bias, strength_rpow, strength_spow, pord, autogain, luma_threshold, show_info")

( comparison == false) ? last : StackHorizontal(clip,last)

}
Thanks
Bernardd is offline   Reply With Quote
Old 5th June 2014, 01:36   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,335
"i do not get the highest frame pixel value"

Well, yes of course you do.
Code:
RT_RgbChanStats(clip c,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,
      float "threshold"=0.0,int "chan"=0,int "lo"=128,int "hi"=lo,int "flgs"=255,string "prefix"="RCS_",
      float "mu"=0.0,int "d"=1,int "p"=1,int "u"=1,int "mask"=NOT_USED, int "MaskMin"=128,"MaskMax"=255)
  Returns multiple results as for above single frame RGB channel sampling functions as Local Variables (prefixed with the prefix string arg).
  The args up to "interlaced", are as for all other clip functions, "threshold" used only for "RT_RgbChanMin", "RT_RgbChanMax" and
  "RT_RgbChanMinMaxDifference" equivalent routines with same functionality.
  "lo" and "hi" are used only with the "RT_RgbChanInRange" equivalent routine with same functionality.
  "mu" and "d" and "p" and "u" are used only with the "RT_RgbChanPNorm" equivalent routine with same functionality.
  The new arg "Flgs" selects which results you want returned and the string "Prefix" that is prepended
  to the returned Local variable names.
  The actual return result is a copy of the flgs args with any non valid bits reset, ie the Local variables that were set.
  Local variables are NOT altered for any function not selected in flgs.
  Returns 0 if no pixels found in search area of mask within MaskMin and MaskMax.

  Flgs_Bit_Number   Add_To_Flgs     Equivalent_Function             Local_Var_Set_Excluding_Prefix_and_Chan_postfix
     0                 1($01)        RT_RgbChanMin()                     "Min"        (0->255)
     1                 2($02)        RT_RgbChanMax()                     "Max"        (0->255)
     2                 4($04)        RT_RgbChanMinMaxDifference()        "MinMaxDiff" (0->255)
     3                 8($08)        RT_RgbChanMedian()                  "Med"        (0->255)
     4                16($10)        RT_RgbChanAve()                     "Ave"        (0.0->255.0)
     5                32($20)        RT_RgbChanStdev()                   "Stdev"      (0.0->255.0)
     6                64($40)        RT_RgbChanInRange()                 "InRng"      (0.0->1.0)
     7               128($80)        RT_RgbChanPNorm()                   "PNorm"      (0.0->??? depends upon d and u)
  The Channel Postfix is of the form "_0", where 0 is RED, 1 is GREEN and 2 is Blue, 3 is ALPHA(RGB32 ONLY), and is appended to the
  base name described above. So eg RT_RgbChanMin for RED channel 0 with default Prefix is "RCS_Min_0".
  RT_RgbChanstats() allows you to inquire multiple results simultaneously, with not much more overhead than calling a single individual
  routine, however, you should not select sub functions that you dont need as there may be an additional unnecessary overhead.
  The Default flgs=255($FF) are all bits set and so sets ALL Local vars at once.
  RT_RgbChanStats(flgs=1+2+16) would set Local vars "RCS_Min_0", "RCS_Max_0" and "RCS_Ave_0" for full frame current_frame, Red Channel.

  In addition to above Local Variables, RT_RgbChanStats() sets an int Local variable (where default prefix) of "RCS_PixelCount_0" being
  the number of Red Channel pixels in mask area X,Y,W,H between MaskMin and MaskMax inclusive.

  NOTE, RT_RgbChanStats() allows Chan to be -1, where ALL three R, and G, and B channels are processed simultaneouly for ALL functions
   selected by flgs arg (ALPHA Channel is NOT processed).
   A chan arg of -2 (RGB32 ONLY allowed) will additionally process the ALPHA channel as well as R+G+B.
  Also Note, (where default Prefix) RCS_PixelCount_x is also set (identically) for all channels when Chan == -1 or -2.
  NOTE, If no valid flg bits set (eg $FF00), then returns 0, RCS_PixelCount_x and all other variables remain as before call.
  Assuming some valid flg bits, if no valid pixels were found in mask then function returns 0, and only RCS_PixelCount_x would be set
  to 0, no other variables are touched (remain as before call, undefined if not previously existing).
  Example usage:
    ScriptClip("""
      got = RT_RgbChanStats(c,mask=Mask,chan=-1,flgs=$10) # Ave
      (got != 0)
        \ ? RT_Debug(RT_String("AveR = %f AveG = %f AveB = %f Pixels = %d",RCS_Ave_0,RCS_Ave_1,RCS_Ave_2,RCS_PixelCount_0))
        \ : RT_Debug("NO VALID PIXELS FOUND")
    """)
That's the one fix for everything version, but there are of couse individual functions.

However, dont know how you do the 'top down contrast', probably mt_tools would be best bet.

EDIT: although he may have done some kind of whole clip scan, twas a long time ago, rather than single frame.
take a peek, you sounded at an earlier post as though you were a C coder.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 5th June 2014 at 01:38.
StainlessS is offline   Reply With Quote
Old 5th June 2014, 22:53   #19  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Thanks StainlessS,
It is for me a new world. I have need time for understand. I should come back if i find a solution.
Thanks, RGBAdapt is a great plugin to manual search and find perfect color.
Bernardd is offline   Reply With Quote
Old 10th June 2014, 18:47   #20  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 180
Hi StainlessS,

Without use RT_RgbChanStats, i have found a effective solution with difference between clip in RGB and clip in greyscale.
Auto white balance with RGBAdapt or ColorYUV2 are now ok.
Because i have not the same start datas, autogain functions have not the same approach in this two last script versions.

Code:
function RGBAdapt_half_auto(clip clip, bool "awb", bool "autogain", \
             float "R_bias_manu", float "R_gain_manu", float "R_cont_manu", float "R_rpow_manu", float "R_spow_manu", float "R_spmid", bool "R_pord",\
             float "G_bias_manu", float "G_gain_manu", float "G_cont_manu", float "G_rpow_manu", float "G_spow_manu", float "G_spmid", bool "G_pord",\
             float "B_bias_manu", float "B_gain_manu", float "B_cont_manu", float "B_rpow_manu", float "B_spow_manu", float "B_spmid", bool "B_pord",\
             float "strength_bias", float "strength_rpow", float "strength_spow", float "strength_autogain",\
             bool "show_info", bool "comparison")

{

#----------------------------------------------based on  RGBADapt plugin ---------------------------------------------------------------------#
#                 script author  : StainlessS http://forum.doom9.org/showthread.php?p=1681286#post1681286                                     #
#

#---------------------------------------------- need  GRunT plugin ----------------------------------------------------------------------------#
#                 script author  : Gavino http://forum.doom9.org/showthread.php?p=1157083#post1157083                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #
                                        
Assert(clip.IsRGB, "RGBAdapt-auto: source must be RGB")

awb = Default(awb,false) # Auto white balance
awb_nb = (awb == false) ? 0 : 1
autogain = Default(autogain, false) # Autogain

R_bias_manu = Default(R_bias_manu, 0)  # same range with original R_bias args 
G_bias_manu = Default(G_bias_manu, 0)  # same range with original G_bias args
B_bias_manu = Default(B_bias_manu, 0)  # same range with original B_bias args

R_gain_manu = Default(R_gain_manu, 1)  # It is original R_gain args, range -8 to 8 center 1.0
G_gain_manu = Default(G_gain_manu, 1)  # It is original G_gain args, range -8 to 8 center 1.0
B_gain_manu = Default(B_gain_manu, 1)  # It is original B_gain args, range -8 to 8 center 1.0

R_cont_manu = Default(R_cont_manu, 1)  # It is original R_cont args, range -8 to 8 center 1.0
G_cont_manu = Default(G_cont_manu, 1)  # It is original G_cont args, range -8 to 8 center 1.0
B_cont_manu = Default(B_cont_manu, 1)  # It is original B_cont args, range -8 to 8 center 1.0

R_rpow_manu = Default(R_rpow_manu, 0)  # range -0.8 to 3.0 center 0 (original R_rpow range 0.1 to 4.0 center 1.0)
G_rpow_manu = Default(G_rpow_manu, 0)  # range -0.8 to 3.0 center 0 (original G_rpow range 0.1 to 4.0 center 1.0)
B_rpow_manu = Default(B_rpow_manu, 0)  # range -0.8 to 3.0 center 0 (original B_rpow range 0.1 to 4.0 center 1.0)

R_spow_manu = Default(R_spow_manu, 0)  # range -0.8 to 3.0 center 0 (original R_spow range 0.1 to 4.0 center 1.0)
G_spow_manu = Default(G_spow_manu, 0)  # range -0.8 to 3.0 center 0 (original G_spow range 0.1 to 4.0 center 1.0)
B_spow_manu = Default(B_spow_manu, 0)  # range -0.8 to 3.0 center 0 (original B_spow range 0.1 to 4.0 center 1.0)

R_spmid = Default(R_spmid, 0.5)  # It is original R_spmid args, range 0.1 to 0.99 center 0.5
G_spmid = Default(G_spmid, 0.5)  # It is original G_spmid args, range 0.1 to 0.99 center 0.5
B_spmid = Default(B_spmid, 0.5)  # It is original B_spmid args, range 0.1 to 0.99 center 0.5

R_pord = Default(R_pord, false)  # It is original R_pord args
G_pord = Default(G_pord, false)  # It is original G_pord args
B_pord = Default(B_pord, false)  # It is original B_pord args

strength_bias = Default(strength_bias, 0.8) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
strength_rpow = Default(strength_rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
strength_spow = Default(strength_spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0
strength_autogain = Default(strength_autogain,0.1) # Spow curve use strength, between 0.0 and 4.0, default 1.0

show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false

neutre =  BlankClip( clip,pixel_type="RGB32", color=$000000)
luma = Greyscale(clip, matrix="Rec601") 
red=ShowRed(clip,"RGB32")
green = ShowGreen(clip,"RGB32")
blue = ShowBlue(clip,"RGB32")

 ScriptClip(clip, """

#------------ RGB values calcul

    r_luma = RGBDifference(luma, neutre) 
    g_luma = RGBDifference(luma,neutre) 
    b_luma = RGBDifference(luma,neutre)
    r = RGBDifference(neutre, red) 
    g = RGBDifference(neutre,green) 
    b = RGBDifference(neutre,blue)  
    
#----------- RGB correction calcul    
    dr = r_luma-r
    dg = g_luma-g
    db = b_luma-b
   
#-----------  RGB correction with linear curve calcul (Bias)   
        dr1_calcul = dr * strength_bias * awb_nb + R_bias_manu
        dr1_low_limit = Max (dr1_calcul, -512)
    dr1 = Min (512, dr1_low_limit)    
        dg1_calcul = dg * strength_bias * awb_nb + G_bias_manu
        dg1_low_limit = Max (dg1_calcul, -512)
    dg1 = Min (512, dg1_low_limit)
        db1_calcul = db * strength_bias * awb_nb + B_bias_manu
        db1_low_limit = Max (db1_calcul, -512)
    db1 = Min (512, db1_low_limit)
    
#-----------  RGB correction with Rpow and Spow curves calcul    
    dr2 = (dr - dr * strength_bias) * awb_nb
    dg2 = (dg - dg * strength_bias) * awb_nb
    db2 = (db - db * strength_bias) * awb_nb
    
#-----------  RGB correction with Rpow curve calcul        
        yr_calcul = exp((dr2/100) * strength_rpow) + R_Rpow_manu
        yr_low_limit = Max (yr_calcul, 0.1)
    yr = Min (4.0, yr_low_limit)
        yg_calcul = exp((dg2/100) * strength_rpow) + G_Rpow_manu
        yg_low_limit = Max (yg_calcul, 0.1)
    yg = Min (4.0, yg_low_limit)
        yb_calcul = exp((db2/100) * strength_rpow) + B_Rpow_manu
        yb_low_limit = Max (yb_calcul, 0.1)
    yb = Min (4.0, yb_low_limit)
    
#-----------  RGB correction with Spow curve calcul    
        sr_calcul = exp((dr2/100) * strength_spow)  + R_spow_manu
        sr_low_limit = Max (sr_calcul, 0.1)
    sr = Min (4.0, sr_low_limit)
        sg_calcul = exp((dg2/100) * strength_spow)  + G_spow_manu
        sg_low_limit = Max (sg_calcul, 0.1)
    sg = Min (4.0, sg_low_limit)
        sb_calcul = exp((db2/100) * strength_spow)  + B_spow_manu
        sb_low_limit = Max (sb_calcul, 0.1)
    sb = Min (4.0, sb_low_limit)
    
#----------- RGB autogain
    f = (autogain ==true ) ? (r+g+b)/(r_luma+g_luma+b_luma) :0
        
        gr_calcul = R_gain_manu + f * strength_autogain/2
        gr_low_limit = Max (gr_calcul, -8.0)
    gr = Min (8.0, gr_low_limit)
        gg_calcul = G_gain_manu + f * strength_autogain/2
        gg_low_limit = Max (gg_calcul, -8.0)
    gg = Min (8.0, gg_low_limit)
        gb_calcul = B_gain_manu + f * strength_autogain/2
        gb_low_limit = Max (gb_calcul, -8.0)
    gb = Min (8.0, gb_low_limit)
    
        cr_calcul = R_cont_manu + f * strength_autogain
        cr_low_limit = Max (cr_calcul, -8.0)
    cr = Min (8.0, cr_low_limit)
        cg_calcul = G_cont_manu + f * strength_autogain
        cg_low_limit = Max (cg_calcul, -8.0)
    cg = Min (8.0, cg_low_limit)
        cb_calcul = B_cont_manu + f * strength_autogain
        cb_low_limit = Max (cb_calcul, -8.0)
    cb = Min (8.0, cb_low_limit)
   
           
   (show_info == false)? \
    RGBAdapt( \
    R_Bias = dr1, R_Gain = gr, R_Cont = cr, R_RPow = yr, R_Spow = sr, R_SPMid = R_spmid, R_Pord = R_pord, \
	 G_Bias = dg1, G_Gain = gg, G_Cont = cg, G_RPow = yg, G_Spow = sg, G_SPMid = G_spmid, G_Pord = G_pord,\
	 B_Bias = db1, B_Gain = gb, B_Cont = cb, B_RPow = yb, B_Spow = sb, B_SPMid = B_spmid, B_Pord = B_pord):\
	 RGBAdapt( \
    R_Bias = dr1, R_Gain = gr, R_Cont = cr, R_RPow = yr, R_Spow = sr, R_SPMid = R_spmid, R_Pord = R_pord, \
	 G_Bias = dg1, G_Gain = gg, G_Cont = cg, G_RPow = yg, G_Spow = sg, G_SPMid = G_spmid, G_Pord = G_pord,\
	 B_Bias = db1, B_Gain = gb, B_Cont = cb, B_RPow = yb, B_Spow = sb, B_SPMid = B_spmid, B_Pord = B_pord)\
	.Subtitle("Red value : "+String(r)+\
	          "\n     Middle - Red Value : "+String(dr)+\
	          "\n Bias : "+String(dr1)+\
	          "\n     Gamma and S correction base : "+String(dr2)+\
	          "\n Rpow : "+String(yr)+"            Spow : "+String(sr),y=40,lsp=20)\
   .Subtitle("Green value : "+String(g)+\
             "\n     Middle - Green Value : "+String(dg)+\     
             "\n Bias : "+String(dg1)+\
             "\n     Gamma and S correction base : "+String(dg2)+\
             "\n Rpow : "+String(yg)+"           Spow : "+String(sg),y=160,lsp=20)\
    .Subtitle("Blue value : "+String(b)+\
             "\n     Middle - Blue Value : "+String(db)+\
             "\n Bias : "+String(db1)+\
             "\n     Gamma and S correction base : "+String(db2)+\
             "\n Rpow : "+String(yb)+"             Spow : "+String(sb), y=280,lsp=20)\
    .Subtitle("Greyscale Value : "+String(r_luma)+"        Contrast gain : "+String(f), y=400,lsp=20)
    	 
""", args = "R_bias_manu, R_gain_manu, R_cont_manu, R_rpow_manu, R_spow_manu, R_spmid, R_pord," +\
                   "G_bias_manu, G_gain_manu, G_cont_manu, G_rpow_manu, G_spow_manu, G_spmid, G_pord,"+\
                   "B_bias_manu, B_gain_manu, B_cont_manu, B_rpow_manu, B_spow_manu, B_spmid, B_pord,"+\
                   "neutre, red, green, blue,luma,"+\
                   "awb_nb, autogain,"+\
                   "strength_bias, strength_rpow, strength_spow, strength_autogain,"+\
                   "show_info")


(comparison == false) ? last : StackHorizontal(clip,last)

}
Code:
function ColorYUV2_auto(clip clip, float "strength_bias",float "strength_Rpow", float "strength_Spow", int "pord",\                 
                                        float "luma_threshold", float "strength_autogain", bool "show_info", bool "comparison")

{

#----------------------------------------------based on  ColorYUV2 plugin ---------------------------------------------------------------------#
#                 script author  : StainlessS http://forum.doom9.org/showthread.php?p=1443313#post1443313                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #                                        

#---------------------------------------------- need  GRunT plugin ----------------------------------------------------------------------------#
#                 script author  : Gavino http://forum.doom9.org/showthread.php?p=1157083#post1157083                                     #
#------------------------------------------------------------------------------------------------------------------------------------------------- #
                                       

strength_bias = Default(strength_bias, 0.5) # linear curve use strength, between 0.0 and 1.0, default 0.5                                 
strength_Rpow = Default(strength_Rpow,1.0) # Rpow curve use strength, between 0.0 and 4.0, default 1.0
strength_Spow = Default(strength_Spow,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0
pord = Default(pord,1) # process Rpow curve before Spow curve or not (1), default 0

luma_threshold = Default(luma_threshold, 0.50)
strength_autogain = Default(strength_autogain,1.0) # Spow curve use strength, between 0.0 and 4.0, default 1.0  # selected luma value percentage for calculation, too weak can be cause of light flicker

show_info = Default(show_info, false) # show info or not, default false
comparison = Default(comparison, false) # show original vs processed comparison  or not, default false
                                       
ScriptClip(clip, """ 

#-------------------------------------------- 
#               Autowhite process
#-------------------------------------------- 
 
#------------ UV average values
    u = AverageChromaU()
    v = AverageChromaV()
    
#----------- UV corrections calculation       
    du = 127.0 - u
    dv = 127.0 - v
    
#-----------  UV corrections with linear curve calculation (Offset)       
    du1 = du*strength_bias
    dv1 = dv*strength_bias
    
#-----------  UV corrections range with Rpow and Spow curves calculation    
    du2 = du-du1
    dv2 = dv-dv1
    
#-----------  UV corrections with Rpow curve calculation       
    ru = du2*strength_rpow 
    rv = dv2*strength_rpow
    
#-----------  UV corrections with Spow curve calculation
    su = du2*strength_spow
    sv = dv2*strength_spow
    
#-------------------------------------------- 
#               autogain process
#--------------------------------------------    
    
#------------ Y max and min values
        
    y_max_value = float(YPlaneMax(threshold = luma_threshold))
    y_max = min (y_max_value, 235.0)
    y_min_value = float(YPlaneMin(threshold = luma_threshold))
    y_min = max (16.0, y_min_value)
    
#-----------  Y gain correction calculation    
    
    f = float(219.0/(y_max - y_min)) #(autogain == true) ?  : 1.0
    gy = (256.0*f-256.0)*strength_autogain
    
#-----------  Y offset correction calculation    
    new_y_max = y_max * f # only for display
    new_y_min = y_min * f
    dy = (16.0 - new_y_min)*strength_autogain  
    
(show_info == false) ? \
     ColorYUV2(\
     gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\
		 :\
		ColorYUV2(\
		gain_y = gy, off_y = dy,\
		off_u = du1, rpow_u = ru, spow_u = su, pord_u = pord,\
		off_v = dv1, rpow_v = rv, spow_v = sv, pord_v = pord)\		
     .Subtitle(" U Chroma value : "+String(u)+"\n"+\
               "     Middle - U Chroma value : "+String(du)+"\n"+\
               " Bias : "+String(du1)+"\n"+\
               "     Gamma and S correction base : "+String(du2)+"\n"+\
               " Rpow : "+String(ru)+"         Spow : "+String(su),y=40,lsp=20)\
      .Subtitle(" V value : "+String(v)+"\n"+\
               "     Middle - V Chroma value : "+String(dv)+"\n"+\
               " Bias : "+String(dv1)+"\n"+\
               "     Gamma and S correction base : "+String(dv2)+"\n"+\
               " Rpow : "+String(rv)+"          Spow : "+String(sv),y=160,lsp=20)\
      .Subtitle(" Y max : "+String(y_max)+"           Y min : "+String(y_min)+"\n"+\
                " luma_threshold : "+String(luma_threshold)+ "           strength_autogain : "+String(strength_autogain)+"\n"+\
                "    Y factor : "+String(f)+"         Y gain : "+String(gy)+"         Y offset : "+String(dy)+"\n"+\
                " New Y max : "+String(new_y_max + dy)+"  New Y min : "+String(new_y_min + dy),y=280,lsp=20)
		
""", args = "strength_bias, strength_rpow, strength_spow, pord, luma_threshold, strength_autogain, show_info")

( comparison == false) ? last : StackHorizontal(clip,last)

}
Auto white balance with RGBAdapt seem a little best auto white balance with ColorYUV. Perhaps it is because the args ranges are not the same, and so
i do not compare the same strength action. Perhaps it is because my RGBAdapt script has not 16-235 range limitation, before convertTo YV12.

Do you agree my analysis or is it something i have not understood ?

Thanks
Bernardd is offline   Reply With Quote
Reply

Tags
rgbadjust

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 05:30.


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