View Full Version : Use difference to decide which pixels to return from 2 clips?
shoopdabloop
5th October 2009, 15:10
basically, i am trying to work with two clips, let's call them a and b. what i want to do is (for each pixel):
if a minus b is greater than a certain amount, use b for that pixel. otherwise, use a.
i've already done it like this:
AviSource("Tape 5 - Clip 007.avi").AssumeBFF()
edi = nnedi2(field=-2)
a = edi.selecteven()
b = edi.selectodd()
c = mt_lutxy(a,b,"x y -",u=3,v=3).mt_binarize(2)
return mt_merge(a,b,c,u=3,v=3)
but i have a feeling there is a more proper way to do it.
Didée
5th October 2009, 15:25
th = 7 # the threshold for max. difference
mt_lutxy( a, b, "x y - abs "+string(th)+" < x y ?", U=3,V=3 )
That's the *how*, and easy enough. For the *why*, I'm not so sure ...
g-force
5th October 2009, 15:28
beaten to the punch
-G
shoopdabloop
6th October 2009, 00:32
a = edi.selecteven()
b = edi.selectodd()
c = mt_lutxy(a,b,"x y -",u=3,v=3).mt_binarize(2)
return mt_merge(a,b,c,u=3,v=3)
http://img96.imageshack.us/img96/2203/yays.png
a = edi.selecteven()
b = edi.selectodd()
th = 7
return mt_lutxy( a, b, "x y - abs "+string(th)+" < x y ?", U=3,V=3 )
http://img39.imageshack.us/img39/9981/nay.png
if i change th, i get a weird effect but it is not the one shown in the first example..
remember, what i'm trying to do is
if: a-b > th
then: use b
else: use a
Didée
6th October 2009, 01:16
Well, how to put it ...
You said:
what i want to do is (for each pixel):
if a minus b is greater than a certain amount, use b for that pixel. otherwise, use a.
The point is that my script does exactly what you described.
It's your initial script that does *NOT* exactly that. Your "x y -" operation does only consider the cases where x > y. The cases where y>x get lost (zero mask).
If you want the same behaviour as your initial script from the mt_lutxy one-liner, just remove the " abs" from the string.
edit: in different words, your initial script will only darken the 1st clip, never lighten it. So you don't really get "cloned objects" - you get that only for (small) dark objects moving over a brighter background. For (small) bright objects moving over a darker background, your initial script will not produced "cloned" objects.
Whichever way one might turn it: the resut is not kosher.
shoopdabloop
6th October 2009, 02:37
oh, so what is the proper way to return the cloning effect?
the reason i am trying to do this, is to merge two clips without "weakening" the areas where they do not agree, as is the case with simple averaging.
Didée
6th October 2009, 02:51
That's what I assumed that you are aiming for. Bad news is that's a difficult effect to achieve in a "proper" way.
The naked pixel values don't give any hint which of both pixels should be used for the output pixel. Hey, c'mon: in frame N, you have a pixel with value "120". In frame N+1, that pixel has the value "160". Now, which to use for the output pixel? The "120" one, because it is darker? Why? The "160" one, because it is brighter? Why?
It won't work that way. If at all, you'd have to compare the signal envelope, and use that one that has the bigger peak at the given location. But while that's more balanced, most probably it'll produce artifacts, too.
Really, I don't see a "proper" way to achieve this without negative side-effecs.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.