View Full Version : Is there a plugin or function for luma matching of two clips?
Avisynth_challenged
13th June 2008, 13:14
Hi to all. I have a question for the community here.
I have 2 clips (Huffyuv YUY2). The clips are two A-to-D captures of an analog source, and both have been trimmed to equal length.
The problem is that one clip is brighter than the other. Here are some screenshots (with histograms) to show the difference in brightness.
CLIP1 (correct brightness): (http://i252.photobucket.com/albums/hh18/FoolsTalk/CLIP1.png)
CLIP2 (too bright): (http://i252.photobucket.com/albums/hh18/FoolsTalk/CLIP2.png)
I want to average the two clips together, so my question is this: does either an Avisynth plugin or a script function exist which would allow me to match CLIP2's brightness to that of CLIP1? Would Subtract() be of any use here?
Thanks in advance to any advice/suggestions! :thanks:
Gavino
13th June 2008, 13:34
Merge (http://avisynth.org/mediawiki/Merge) should do what you want.
thetoof
13th June 2008, 16:26
Wouldn't merge take the luma for a clip to put it in the other one? From what I understand, he wants to compare those luma values to reduce clip2's brightness, not take the ones from clip1 and put them in clip2.
I'm not sure how, but but maybe something in the masktools can do the job?
You could also do it manually with tweak...
Gavino
13th June 2008, 17:54
He said he wanted to average the two clips together - Merge (with default parameters) does exactly that, there is an example of this in the documentation.
Using the weight parameter, the two clips can be combined in any proportion. To keep the original chroma, use MergeLuma instead of Merge (but note that it has a different default for weight).
Avisynth_challenged
13th June 2008, 18:27
Hey, thanks for the responses :)
@Gavino:
Yes, I do want to average, but the reason for doing so is to reduce random (gaussian) video noise. I will have 3 identical length clips (from 3 captures of the same source), and I want to do a perfect averaging of all 3 of them.
CLIP1 has correct brightness, while CLIP2 is too bright. But instead of using Merge() or MergeLuma() to take the average brightness of the two, I'd rather correct CLIP2's level so that it matches CLIP1. That way, I'll have CLIP1's unique Y information (with correct brightness level) to average with CLIP2's unique Y information (with fixed brightness level), so that the net result is lower gaussian video noise on the Y channel.
Now if I do any Merge() functions, CLIP2's Y channel will be mixed with CLIP1's (and if I choose "weight=1", CLIP2's Y channel would be replaced with CLIP1's Y channel). This would have the net effect of weighting the gaussian noise closer to CLIP1, whereas I would much rather prefer to have the two gaussian samples weighted at 50/50 when I take the average (actually I'll have 3 sample clips to average, so the weighting would be 33.3/33.3/33.3). So all clips must have the same brightness level, but they also must retain their own Y information.
I hope I'm making sense here. Thanks for the suggestions so far. I'm very grateful to the Doom9 forum community :)
Gavino
13th June 2008, 20:20
Ah, so ultimately you do want to Merge (or MergeLuma), but before doing so, you want to 'normalise' clip2 using clip1 as a reference?
Do you know if clip2 is brighter than clip1 by a constant amount or by a constant factor? If so, ColorYUV with appropriate values of gain_y and/or off_y should do the trick.
Or is the difference even frame-dependent? In that case, you might need to use a run-time script, something like:
clip2_norm = ScriptClip(clip2, """
y1 = AverageLuma(clip1)
y2 = AverageLuma() # ie clip2
# now use ColorYUV with gain_y and/or off_y and values derived from y1 and y2
ColorYUV( ... )
""")
gzarkadas
13th June 2008, 21:17
@Avisynth_Challenged,
Maybe Clouded's plugins Colourlike (http://forum.doom9.org/showthread.php?t=96308) and Average (http://forum.doom9.org/showthread.php?t=100626) are what are you looking for. There are links at New Plugins and Utilities (http://forum.doom9.org/showthread.php?t=84481) thread; you can also get them from this thread (http://forum.doom9.org/showthread.php?t=118430).
Didée
13th June 2008, 21:30
I'd try to take a lowpass from the first clip, average the highpasses from all three clips, and merge that average onto the lowpass. That method is mostly independent of the exact type of the luma levels differences.
Avisynth_challenged
14th June 2008, 03:28
Thanks again for the ongoing discussion.
@gzarkadas:
Colourlike looks promising. I have a question, if you know how it works. I successfully created two "histogram.txt" output files, for 2 different clips. One clip was 4 frames long, and the other clip was 105,150 frames long. The histogram.txt file for the 4 frame clip was 5K in size, while the histogram.txt file for the 105,150 frame clip was 6K in size. Is this normal? Are all histogram output files about the same filesize, regardless of the length of the clip that was used to generate them? I was expecting the histogram file of the 105,150 frame clip to be >> than the histogram file of the 4 frame clip.
@Didée
I'm not clear on what you suggested. Could you elaborate on lowpass and highpass averaging? Please pardon my ignorance but I am, as my username says, Avisynth challenged. :stupid:
Thanks again to this excellent community.
Didée
14th June 2008, 09:52
Something like this:
# VariableBlur.dll , mt_masktools.dll , Average.dll
clip1 = XYZsource(...) # <-- this' the one with "correct" luma levels
clip2 = XYZsource(...) # /-- perhaps too bright, eventually too dark,
clip2 = XYZsource(...) # \-- who knows, who cares ...
LOP1 = clip1.BinomialBlur(vary=6.66, varc=6.66, Y=3,U=3,V=3)
LOP2 = clip2.BinomialBlur(vary=6.66, varc=6.66, Y=3,U=3,V=3)
LOP3 = clip3.BinomialBlur(vary=6.66, varc=6.66, Y=3,U=3,V=3)
HIP1 = mt_MakeDiff( clip1, LOP1, Y=3,U=3,V=3)
HIP2 = mt_MakeDiff( clip2, LOP2, Y=3,U=3,V=3)
HIP3 = mt_MakeDiff( clip3, LOP3, Y=3,U=3,V=3)
HIP_avg = Average(HIP1,1./3, HIP2,1./3, HIP3,1./3)
LOP1.mt_AddDiff(HIP_avg, Y=3,U=3,V=3)
This does also chroma in the same way. To process only luma, set U=2,V=2 in the last line, and U=1,V=1 everywhere else.
Gavino
14th June 2008, 10:40
@Didée: Can you explain the theory behind your method?
I can see that it will produce a clip with the brightness of clip1 and will eliminate any systematic luma offset in clips 2 and 3. When clip2 (or clip3) has a systematic luma gain wrt clip1, doesn't it still give excessive weight to that clip's noise when averaging?
(Perhaps this is what you meant by mostly independent of the type of luma difference?)
2Bdecided
16th June 2008, 14:59
I'd just average the three clips together, and then worry about the brightness.
Either the brighter clip is clipped (peak white chopped off), in which case you shouldn't use it at all, or it's not - in which case, merge it into the others and change the brightness as needed.
FWIW, a lot of the noise in those two PNGs is common to both images - averaging them isn't going to remove it.
So try the quick and dirty "merge them all together" method first - the results might be surprisingly good, or disappointingly bad - and either way, you've avoided answering the question at the top of this thread!
Cheers,
David.
Avisynth_challenged
19th June 2008, 05:49
I've decided to go with the Colourlike() option.
My source is YUY2, but Colourlike requires YV12. I want to modify the luma only, so I came up with this script to keep my original chroma intact:
### BEGIN SCRIPT ###
source=directshowsource("c:\...\fixthisluma.avi")
sourceyv12=source.converttoyv12()
lumafix=sourceyv12.colourlike("d:\...\luma_fix.txt", "d:\...\luma_ref.txt")
lumatweak=lumafix.converttoyuy2().mergechroma(source)
final=lumatweak
return final
### END SCRIPT ###
Preliminary tests are very good. I'll post screenshots later. Thanks to everyone for all the help. :thanks:
AVIL
19th June 2008, 07:30
Hi,
Colourlike could be used with RGB32 clips also (sintax is the same, logically last three boolean parameters apply to R - G - B instead Y - U - V).
Good luck
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.