Log in

View Full Version : MaskMerging multiple clips


redfordxx
18th May 2006, 09:05
Hi

can anybody tell me best way, how to mask merge more clips to avoid the rounding error as much as possible.
There would be two kinds of merging in my script:
[((((c0*m1+(255-m1)*c1)*m2+(255-m2)*c2)*m3+(255-m3)*c3)*m4+(255-m4)*c4)...]/255or[c1*w1+c2*w2+c3*w3+c4*w4+c5*w5...]/255c?...clip
m?...mask clip (like for mt_merge)
w?...weight clip for merging

For example merging 255 clips of color 100 with weight 1 should result in clip color 100, but due to rounding would lead to black clip - color 0.
Well, I won't merge such a number of clips, but for examle it is good.

Thanks for all suggestions...

AVIL
18th May 2006, 10:08
Hi,

In the second case you can try mg262's (a.k.a. clouded) average filter. See the thread:

http://forum.doom9.org/showthread.php?t=100626

The weights are floats then it could be as accurate as you need. It's fast also.

Good luck

P.S. After a second read I'll see that weights must come from a clip. My suggestion failed as clouded's filters uses constants as weigths.

foxyshadis
18th May 2006, 11:45
I don't know of any more general version of mt_lutxy, which means it's a great candidate for a new filter =p but if you can deal with obscne manual labor, you can double the precision of merges by using two lutxys, each expanding half the range into the full range. Add more to get more precision and probably exponentially increase the number of statements needed to merge them all eventually...

redfordxx
18th May 2006, 14:18
I don't know of any more general version of mt_lutxy, which means it's a great candidate for a new filter
Really,"x1 x2 * x3 x4 * x5 x6 * x7 x8 * x9 x10 * + + + + 255 /"looks very nice...
... well, now I recalled the principle of lut (precalculation) can't be used for it'll run out of memory, but still, normal calculation...
but if you can deal with obscne manual labor, you can double the precision of merges by using two lutxys, each expanding half the range into the full range. Add more to get more precision and probably exponentially increase the number of statements needed to merge them all eventually...
not sure, whether you mean something like this, but I tried: clip1=...
clip2=...
weight1=...
weight2=...
c1a=clip1.mt_lut("x 2 *")
c1b=clip1.mt_lutxy(c1a,"x 2 * y -")
c2a=clip2.mt_lut("x 2 *")
c2b=clip2.mt_lutxy(c2a,"x 2 * y -")
cw1a=mt_lutxy(c1a,weight1,"x y * 255 /")
cw1b=mt_lutxy(c1b,weight1,"x y * 255 /")
cw2a=mt_lutxy(c2a,weight2,"x y * 255 /")
cw2b=mt_lutxy(c2b,weight2,"x y * 255 /")
Average(cw1a,0.5,cw1b,0.5,cw2a,0.5,cw2b,0.5)
So that would be a weighted average of two clips with double precission.
But dunno how the rounding in all these functions works and whether there should be 255 or 256. Can anybody check so it is properly?