View Single Post
Old 4th June 2014, 23:24   #16  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 249
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