Hello RaffRiff42
Your white balance observations are impressive.
I agree with you. Your method is very subjective and perhaps not mathematically correct. But you show well that luma range selectivity is more important than mathematical correctness for warm colors.
I have changed your script to use auto white balance function of ColorYUV and to display the different luma range outputs for warm color choice.
I have not your perfect masktools knowledge. So i have keep your script part relative to mask creation and use.
What you think about this fork of your process. Do you know limit of this approach ?
Code:
##Last=YUV
## From CheapColorTemp demonstration, mod auto white balance version
## stack between original and several corrections
## (view in step mode; not for real time playback)
StackVertical(
\StackHorizontal(last.Subtitle("original"),CheapColorTempAuto(1,0,0).Subtitle("AWB lo")),
\StackHorizontal(last.Subtitle("original"),CheapColorTempAuto(0,1,0).Subtitle("AWB mid")),
\ StackHorizontal(last.Subtitle("original"),CheapColorTempAuto(0,0,1).Subtitle("AWB hi")),
\StackHorizontal(last.Subtitle("original"),last.ColorYuv(autowhite=true).Subtitle("AWB ColorYuv")))
return last
#######################################
### emulate color temperature changes in three luma ranges
##
##
function CheapColorTempAuto(clip C, int lo_auto, int mid_auto, int hi_auto)
{
Assert(C.IsYUV, "CheapColorTemp: source must be YUV")
lo_auto = Default(lo_auto, 0)
mid_auto = Default(mid_auto, 0)
hi_auto = Default(hi_auto, 0)
return C.ColorYUVxAuto(lo_auto = lo_auto, mid_auto = mid_auto, hi_auto = hi_auto)
}
#######################################
### apply ColorYUV autowhite to three luma ranges
##
## @ xover_x - aproximate 50% luma blend between ranges
## ( no reason to mess with this)
## @ showmasks - if true, show original + 3 masks in quad split
##
function ColorYUVxAuto(clip C,
\ int "lo_auto",int "mid_auto", int "hi_auto",
\ float "xover_lomid", float "xover_midhi",
\ bool "showmasks")
{
lo_auto = Default(lo_auto, 0)
mid_auto = Default(mid_auto, 0)
hi_auto = Default(hi_auto, 0)
xlo = Min(Max( 0, Default(xover_lomid, 102)), 127) * 3.0 / 256
xhi = Min(Max(128, Default(xover_midhi, 191)), 255) * 3.0 / 256
showmasks = Default(showmasks, false)
(lo_auto == 1) ? C.ColorYUV(autowhite=true) : C
C_lo_auto = last
(mid_auto == 1) ? C.ColorYUV(autowhite=true) : C
C_mid_auto = last
(hi_auto == 1) ? C.ColorYUV(autowhite=true) : C
C_hi_auto = last
## mt_lutxyz too slow!!
mask_lo = C.mt_lut(
\ yexpr="x -0.01 * "+String(xlo)+" + 256 * ",
\ u=-128, v=-128)
mask_hi = C.mt_lut(
\ yexpr="1 x -0.01 * "+String(xhi)+" + - 256 * ",
\ u=-128, v=-128)
mask_mid = mt_lutxy(mask_lo, mask_hi, "x y + -1 * 256 + ", u=-128, v=-128)
return (showmasks)
\ ? StackVertical(
\ StackHorizontal(C, mask_lo),
\ StackHorizontal(mask_mid, mask_hi))
\ .BilinearResize(C.Width, C.height)
\ .Subtitle("Low", align=9)
\ .Subtitle("\nMid", align=4, lsp=0)
\ .Subtitle("\nHigh", align=6, lsp=0)
\ : C.Overlay(C_lo_auto, mask=mask_lo)
\ .Overlay(C_mid_auto, mask=mask_mid)
\ .Overlay(C_hi_auto, mask=mask_hi)
}