View Full Version : Average n of x (TooT style)
juhok
11th July 2017, 05:03
The goal: average VHS/etc captures. To get rid of semi random errors caused by analog crappiness.
I've tried:
video = core.misc.AverageFrames([video1, video2, video3, video4, video5], [1,1,1,1,1])
It's decent. But 2/3 ("TooT for Avisynth") or 3/5 or some other weight would be better. No idea how to do it tho.
WolframRhodium
11th July 2017, 06:42
I guess the "TooT or Avisynth" works the same way as the following code according to E-Male's thread (https://forum.doom9.org/showthread.php?p=513183#post513183):
def toot(clipa, clipb, clipc):
absXYMinus = 'x y - abs'
absXZMinus = 'x z - abs'
absYZMinus = 'y z - abs'
xyAverage = 'x y + 2 /'
xzAverage = 'x z + 2 /'
yzAverage = 'y z + 2 /'
expr = '{0} {1} < {0} {2} < {3} {5} ? {1} {2} < {4} {5} ? ?'.format(absXYMinus, absXZMinus, absYZMinus, xyAverage, xzAverage, yzAverage)
return core.std.Expr([clipa, clipb, clipc], [expr])
Above code is so ugly, though:(
Myrsloik
11th July 2017, 11:43
I guess the "TooT or Avisynth" works the same way as the following code according to E-Male's thread (https://forum.doom9.org/showthread.php?p=513183#post513183):
def toot(clipa, clipb, clipc):
absXYMinus = 'x y - abs'
absXZMinus = 'x z - abs'
absYZMinus = 'y z - abs'
xyAverage = 'x y + 2 /'
xzAverage = 'x z + 2 /'
yzAverage = 'y z + 2 /'
expr = '{0} {1} < {0} {2} < {3} {5} ? {1} {2} < {4} {5} ? ?'.format(absXYMinus, absXZMinus, absYZMinus, xyAverage, xzAverage, yzAverage)
return core.std.Expr([clipa, cilpb, clipc], [expr])
Above code is so ugly, though:(
That's creative. Maybe you could throw something together using makediff and merge that may or may not be faster. Probably not though.
WolframRhodium
11th July 2017, 12:37
That's creative. Maybe you could throw something together using makediff and merge that may or may not be faster. Probably not though.
The limited range of an integer format clip is sometimes annoying.
e.g:
diff = MakeDiff(a, b)
a_ = MergeDiff(b, diff)
"a_" is not the same as "a" when there's an overflow:
If a=1, b=254, then diff=0 due to the clipping, so a_=126, not equal to a.
One way I know to solve that is the following:
diff = MakeDiff(a, b)
b_tmp = MakeDiff(a, diff)
a_ = MergeDiff(b_tmp, diff)
Now, if a=1, b=254, then diff=0, and b_tmp=129, so a_=1==a
As for TooT, overflow can affect the decision of which two clips should be averaged, so I do not use MakeDiff.
But sure, there's no problem with Merge, so the code can be:
def toot(clipa, clipb, clipc):
absXYMinus = 'x y - abs'
absXZMinus = 'x z - abs'
absYZMinus = 'y z - abs'
xyAvg = core.std.Merge(clipa, clipb)
xzAvg = core.std.Merge(clipa, clipc)
yzAvg = core.std.Merge(clipb, clipc)
expr = '{0} {1} < {0} {2} < a c ? {1} {2} < b c ? ?'.format(absXYMinus, absXZMinus, absYZMinus)
return core.std.Expr([clipa, clipb, clipc, xyAvg, xzAvg, yzAvg], [expr])
juhok
11th July 2017, 13:43
Thanks a bunch. Can this same principle be expanded to 3 of 5? Seems like there's some very stubborn chroma glitches which fool 2 of 3.
WolframRhodium
11th July 2017, 14:44
Thanks a bunch. Can this same principle be expanded to 3 of 5? Seems like there's some very stubborn chroma glitches which fool 2 of 3.
Sorry I can't do that.
The code will be very long for 3 of 5 when using ternary operator to implement argmin as above. Even for 2 of 5, 2^4=16 operators are required, I think. I'm too lazy to do it, (and I usually make mistakes on such large programs).
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.