View Full Version : sum of squares of differences of Luma - function exists?
TheSeven
6th December 2006, 09:38
* de-Lurk routine activated *
There is something that I have been hunting in vain for, which sounds like it should be simple, for a brute-force and probably ultimately unsuccessful denoising script I'm trying to write:
Is there a function, filter or bit of script that can return the sum of the squares of the differences of the pixel L, U, or V values between two different clips?
I mean for example, to return the value of
sum over i of (sum over j of ( ( L(clip1,i,j) - L(clip2,i,j) )**2 ) )
Thanks...
emmel
6th December 2006, 11:21
There is a built-in function "Compare" for sources is RGB or YUY2, and a plug-in called "CompareYV12" for sources in YV12. The functions return the squared norm of the difference in a logarithmic scale. See docs for more details.
Cheers.
TheSeven
7th December 2006, 01:26
Thanks, I will try to make use of Compare.
It seems however that Compare writes to a text file. I need the data to do scene change detection, so I was hoping to find something that could return the value to a variable within the script....
TheSeven
8th December 2006, 03:18
I hate to bother people but I am truly stuck on this one. I can manage to write the AverageLuma as a subtitle:
video = AVIsource("MyFile.avi")
SourceYV12 = ConvertToYV12(video)
x=100
y=100
SinglePixel = SourceYV12.bilinearresize(128, 128, x,y, 1,1)
FrameEvaluate(ScriptClip(SinglePixel, "SinglePixel.Subtitle(String(LumaVal))"), \
"global LumaVal = AverageLuma(SinglePixel)") # works!!!
which was quite painful to arrive at for poor Noo-Be-Me. But I cannot for the life of me manage to get the value of AverageLuma saved into a variable in the main part of the script where I can do calculations with it. I have tried all varieties and arrangements of ScriptClip's and FrameEvaluate's and function calls and other sorts of grotesqueries that I can think of (I will spare you reading my rubbish script).
I may try to use WriteFile to write the values to a file, hoping that I will manage to use ConditionalReader to read them back, as emmel suggested, but is there a way to get the value of AverageLuma into the main script, or are those values never accessible outside of the conditional filters?
foxyshadis
8th December 2006, 16:01
Once you start working with conditional, you have to stay in conditional as long as you need the numbers that it gives you. Once you're done working and left with just a final video clip, you can leave conditional and get back to the normal flow. (It took me a while to figure out the nuances of conditional, and I've picked up all kinds of crazy languages in my time.) So just keep adding more FrameEvaluates until you have enough information.
This is because within the context of a normal script, a number is constant from the time the script is evaluated. If you happen to know any functional programming, that's how it works.
global ssd=SourceYV12.mt_lut("x 2 ^")
s1=ScriptClip(SourceYV12, """yourfilter(x,y)""")
s3=s2.FrameEvaluate("""global x=lumaval * 10
global y=lumaval*2""")
s3=s2.FrameEvaluate("""global LumaVal = AverageLuma(ssd)""")
s3
TheSeven
8th December 2006, 16:54
If you happen to know any functional programming, that's how it works.
That's (one of) my problems. Much learning to go.
Thanks for the suggestion, I will try it out. I am guessing that you meant to write this?:
global ssd=SourceYV12.mt_lut("x 2 ^")
s1=ScriptClip(SourceYV12, """yourfilter(x,y)""")
s2=s1.FrameEvaluate("""global x=lumaval * 10
global y=lumaval*2""")
s3=s2.FrameEvaluate("""global LumaVal = AverageLuma(ssd)""")
s3
foxyshadis
8th December 2006, 17:04
Oh yes, sorry. Copy-pasted too quickly.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.