PDA

View Full Version : Good way to test two clips in ConditionalFilter


nonoitall
1st June 2007, 23:28
I have a motion compensated clip and I want to selectively replace frames in it that are dissimilar from the original clip by a certain threshold. Basically, a certain amount of luma difference will decide whether the motion compensated clip is too different or not. But I also want to weight this difference against the average luma in the original clip. (For example, a tiny difference on a frame with lots of luma will be ignored, but a tiny difference on a darker frame will have a better chance of going over the threshold.) Here's what I want to do:
#source is the original clip
#mocomp is the motion compensated clip
#abs_difference is a clip with the absolute luma difference between the two
#threshold is a threshold!

new_mocomp = ConditionalFilter(abs_difference, mocomp, source, \
"abs_difference.AverageLuma() / source.AverageLuma()", "<", String(threshold))
Unfortunately, I can only test the average luma of the test clip (abs_difference) and not the source clip (unless, of course, I make source the test clip, in which case I can't test the average luma of the abs_difference clip). For the moment, I stack the two clips together and then crop a couple of times inside the ConditionalFilter function to separate them again, but this seems horribly inefficient. Is there a better way?

foxyshadis
2nd June 2007, 06:06
When you declare the clips, use

global source = last
global abs_difference = .....

Then you should be able to see them in conditionalfilter.

nonoitall
5th June 2007, 08:46
Now it's 'legal' for me to use both clips in ConditionalFilter, but I don't get results consistent with the stack/crop method. (I probably should have mentioned that this is part of a function that gets called on several different motion compensated clips. Then the median of those clips and the original clip is used for the final clip.) If you need me to post some code I can.

PS: Sorry about the long line in my first post, neuron2.

foxyshadis
5th June 2007, 13:15
It'd probably help, if it's a complex one. Being able to see it all at once and test it locally makes helping much easier.

sh0dan
6th June 2007, 09:17
You do realize, you do have
"LumaDifference(clip1, clip2)" as a conditional function.

nonoitall
6th June 2007, 09:54
Well, I started the script from scratch (it was getting really messy since I was learning as I composed it) and now using a global source clip seems to be working! I don't know what I was doing wrong before. (Maybe having the difference clip as a global variable threw things off since it would have been assigned several different clips - a new one for each motion compensated clip I made, but now only the source clip is global, which is a bit more logical anyway.)
You do realize, you do have
"LumaDifference(clip1, clip2)" as a conditional function.
I don't want to determine the average difference between the clips, but the average luma of the difference clip divided by the average luma of the source clip.

Anyway, unless I screw things up again, I think this should work. Thanks!