View Full Version : ColorYUV use
Bernardd
15th March 2014, 01:14
Hello,
Avisynth help say ColorYUV can use conditional variables, and it is possible to modify these variables using FrameEvaluate or ConditionalReader.
So i have tried this
ColorYUV(off_u="-delta",off_v="delta",conditional=true)
FrameEvaluate("delta = float((AverageChromaU()-AverageChromaU())/2)", show=false, after_frame=false)
But i get error off_u wrong type.
Is it problem of avisynth grammar or is this action not allowed ?
Gavino
15th March 2014, 01:59
The conditional variables have fixed names coloryuv_off_u, etc, and are not supplied in the actual call to ColorYUV().
Also, since you want the values to depend on the average chroma of the unfiltered source, you need to put the FrameEvaluate() calls before ColorYUV().
FrameEvaluate("coloryuv_off_u = float((AverageChromaV()-AverageChromaU())/2)")
FrameEvaluate("coloryuv_off_v = float((AverageChromaU()-AverageChromaV())/2)")
ColorYUV(conditional=true)
(I assume there was a typo in your code and you wanted to subtract AverageChromaV from AverageChromaU (or vice versa) - subtracting U from itself doesn't make much sense.)
Bernardd
15th March 2014, 17:41
Thanks Gavino,
Sometime ColorYuv Autowhite function give me cold tone picture, i am searching to improve this.
With your help i can write this short script to compare ColorYuv Autowhite function vs ColorYuv tuned Autowhite function.
a=ScriptClip(""" Subtitle("original",y=10)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_U = " + String(AverageChromaU()),y=40)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_V = " + String(AverageChromaV()),y=60)""")\
.ScriptClip(""" Subtitle("AWB_difference_U_V = " + String(AverageChromaU()-AverageChromaV()),y=80)""")\
.ScriptClip(""" Subtitle("AWB_moyenne_U_V = " + String((AverageChromaU()+AverageChromaV())/2),y=100)""")
b=ColorYUV(autowhite=true).ScriptClip(""" Subtitle("basic autowhite coloryuv",y=10)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_U = " + String(AverageChromaU()),y=40)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_V = " + String(AverageChromaV()),y=60)""")\
.ScriptClip(""" Subtitle("AWB_difference_U_V = " + String(AverageChromaU()-AverageChromaV()),y=80)""")\
.ScriptClip(""" Subtitle("AWB_moyenne_U_V = " + String((AverageChromaU()+AverageChromaV())/2),y=100)""")
facteur = [<"facteur", 0.0, 5.0, 1.0>]
seuil = [<"seuil", 0, 255, 128>]
FrameEvaluate("coloryuv_off_u = float((AverageChromaV()-AverageChromaU())/2)*facteur+ float(seuil-(AverageChromaV()+AverageChromaU())/2)")
FrameEvaluate("coloryuv_off_v = float((AverageChromaU()-AverageChromaV())/2)*facteur +float(seuil-(AverageChromaV()+AverageChromaU())/2)")
c=ColorYUV(conditional=true).ScriptClip(""" Subtitle("tuned autowhite coloryuv",y=10)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_U = " + String(AverageChromaU()),y=40)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_V = " + String(AverageChromaV()),y=60)""")\
.ScriptClip(""" Subtitle("AWB_difference_U_V = " + String(AverageChromaU()-AverageChromaV()),y=80)""")\
.ScriptClip(""" Subtitle("AWB_moyenne_U_V = " + String((AverageChromaU()+AverageChromaV())/2),y=100)""")
return interleave(a,b,c)
Now, i am looking if this coloryuv use is a good idea.
Gavino
15th March 2014, 18:25
a=ScriptClip(""" Subtitle("original",y=10)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_U = " + String(AverageChromaU()),y=40)""")\
.ScriptClip(""" Subtitle("AWB_Average_Chroma_V = " + String(AverageChromaV()),y=60)""")\
.ScriptClip(""" Subtitle("AWB_difference_U_V = " + String(AverageChromaU()-AverageChromaV()),y=80)""")\
.ScriptClip(""" Subtitle("AWB_moyenne_U_V = " + String((AverageChromaU()+AverageChromaV())/2),y=100)""")
You should not use multiple instances of ScriptClip here.
When calling AverageChromaU(), it will be applied to the result of the first ScriptClip(), including the subtitle, rather than the original input. Similarly, each successive call to AverageChromaU() or AverageChromaV() will be applied to the previous subtitled clip in the chain. It's also inefficient, as each ScriptClip instance invokes the Avisynth parser on every frame.
You can put multiple lines (a complete mini-script) inside ScriptClip(), like:
a=ScriptClip("""
acu = AverageChromaU()
acv = AverageChromaV()
Subtitle("original",y=10)
Subtitle("AWB_Average_Chroma_U = " + String(acu),y=40)
Subtitle("AWB_Average_Chroma_V = " + String(acv),y=60)
Subtitle("AWB_difference_U_V = " + String(acu-acv),y=80)
Subtitle("AWB_moyenne_U_V = " + String((acu+acv)/2),y=100)
""")
You could even go further and replace the multiple Subtitle() calls with a single multi-line Subtitle() (using \n and the lsp parameter).
Taking my own advice, I see now that the two FrameEvaluates could also be replaced by a single one:
FrameEvaluate("
U = AverageChromaU()
V = AverageChromaV()
coloryuv_off_u = float((V-U)/2)*facteur+ float(seuil-(V+U)/2)
coloryuv_off_v = float((U-V)/2)*facteur +float(seuil-(V+U)/2)
")
Bernardd
15th March 2014, 22:59
Thousand thanks.
Thanks for the correction of my dummy serie of ScripFile application.
Thanks for the smart FrameEvaluate script amend.
A little last question, are these formulas for color_off_ u and v, the internal formulas used by coloryuv autowhite ?
Gavino
15th March 2014, 23:29
ColorYUV(autowhite=true) does the equivalent of setting off_u = 127-AverageChromaU() and off_v = 127-AverageChromaV().
In other words, it adjusts both U and V to average 127 in the output.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.