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.

 Doom9's Forum Average n of x (TooT style)
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 11th July 2017, 05:03 #1  |  Link juhok Registered User     Join Date: Dec 2005 Posts: 110 Average n of x (TooT style) The goal: average VHS/etc captures. To get rid of semi random errors caused by analog crappiness. I've tried: Code: `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.
 11th July 2017, 06:42 #2  |  Link WolframRhodium Registered User   Join Date: Jan 2016 Posts: 109 I guess the "TooT or Avisynth" works the same way as the following code according to E-Male's thread: Code: ```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 Last edited by WolframRhodium; 11th July 2017 at 12:46.
11th July 2017, 11:43   #3  |  Link
Myrsloik
Professional Code Monkey

Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,002
Quote:
 Originally Posted by WolframRhodium I guess the "TooT or Avisynth" works the same way as the following code according to E-Male's thread: Code: ```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.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet

11th July 2017, 12:37   #4  |  Link
WolframRhodium
Registered User

Join Date: Jan 2016
Posts: 109
Quote:
 Originally Posted by Myrsloik 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:
Code:
```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:
Code:
```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:
Code:
```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])```

Last edited by WolframRhodium; 11th July 2017 at 12:46.

 11th July 2017, 13:43 #5  |  Link juhok Registered User     Join Date: Dec 2005 Posts: 110 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.
11th July 2017, 14:44   #6  |  Link
WolframRhodium
Registered User

Join Date: Jan 2016
Posts: 109
Quote:
 Originally Posted by juhok 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).

Last edited by WolframRhodium; 11th July 2017 at 14:47.