View Full Version : RGBAdjust(analyze=true) on the masked part only?
zee944
24th February 2011, 19:58
I'd like to see the R, G, B values only on the masked part of the video. Is there way to that?
I know I could take the masked part and put it on a black (blank) clip and analyze that, but then the black pixels would also be counted in the analysis, and would lower the R, G, B values. Any ideas?
(As an alternative, perhaps it would enough for me to just see the average luma of the masked part. But probably it's no easier to find out.)
Gavino
24th February 2011, 21:19
If the mask is a binary one, ie contains only 0 or 255 (I'm not sure the question makes sense otherwise), then taking AverageLuma of the mask tells you the proportion of pixels selected. You can then use that to (mentally) scale the values reported by RGBAdjust on the masked+blank clip.
zee944
26th February 2011, 12:22
It doesn't work for me.
ScriptClip(""" \
subtitle( string( RGBDifference(cliptoanalyze.ShowRed(), BlankClip(cliptoanalyze)) * (255 / AverageLuma(mymask.ConvertToYV12)) ),240,100 )\
""")
That would be the basic idea for displaying the Red component, right? Nevertheless, I end up with a value around 57 which should be around 230 in the reality. What's wrong? :(
Gavino
26th February 2011, 12:49
The basic idea looks right.
Show the rest of your script.
Is 'cliptoanalyze' the original clip layered onto a blank clip with the mask?
What form is 'mymask' in? You probably need ConvertToYV12(matrix="PC.601") to preserve full range.
Check the intermediate values look sensible by displaying the average red and the mask average luma separately.
zee944
26th February 2011, 15:42
Is 'cliptoanalyze' the original clip layered onto a blank clip with the mask?
What form is 'mymask' in?
Yes. And 'mymask' is a 0-255 RGB clip.
MPEG2Source("TD_Universe_VideoFile.d2v")
AssumeTFF()
Telecide(guide=1)
Decimate(cycle=5)
AssumeFPS(23.976)
mymask=last.ConvertToRGB32().ResetMask()
mymask=mymask.JDL_ApplyRange(7415,7517,"ColorKeyMask($EA771C,15)")
mymask=ShowAlpha(mymask).Invert()
cliptoanalyze=Overlay(BlankClip(last), last, mask=mymask.ConvertToRGB32()).ConvertToRGB32()
cliptoanalyze
#RGBAdjust(analyze=true)
ScriptClip(""" \
subtitle( "R: "+string( RGBDifference(cliptoanalyze.ShowRed(), BlankClip(cliptoanalyze)) ),100,100 )\
""")
ScriptClip(""" \
subtitle( "G: "+string( RGBDifference(cliptoanalyze.ShowGreen(), BlankClip(cliptoanalyze)) ),100,130 )\
""")
ScriptClip(""" \
subtitle( "B: "+string( RGBDifference(cliptoanalyze.ShowBlue(), BlankClip(cliptoanalyze)) ),100,160 )\
""")
ScriptClip(""" \
subtitle( "mask R: "+string( RGBDifference(cliptoanalyze.ShowRed(), BlankClip(cliptoanalyze)) * (255 / AverageLuma(mymask.ConvertToYV12)) ),240,100 )\
""")
ScriptClip(""" \
subtitle( "mask G: "+string( RGBDifference(cliptoanalyze.ShowGreen(), BlankClip(cliptoanalyze)) * (255 / AverageLuma(mymask.ConvertToYV12)) ),240,130 )\
""")
ScriptClip(""" \
subtitle( "mask B: "+string( RGBDifference(cliptoanalyze.ShowBlue(), BlankClip(cliptoanalyze)) * (255 / AverageLuma(mymask.ConvertToYV12)) ),240,160 )\
""")
#ScriptClip(""" \
# subtitle( string( 1 * (255 / AverageLuma(mymask.ConvertToYV12)) ),440,100 )\
#""")
Interleave(last,mymask)
Gavino
26th February 2011, 16:04
'mymask' is a 0-255 RGB clip.
Then you definitely need to use matrix="PC.601" when converting it to YV12.
However, I don't think that would explain the large difference beween 230 and 57.
You could try replacing Overlay by Layer, which is simpler for RGB32.
Gavino
27th February 2011, 14:59
However, I don't think that would explain the large difference beween 230 and 57.
On second thoughts, it can (and probably does) explain it.
If you omit matrix="PC.601", 255 will be converted to 235 and 0 converted to 16.
If the number of pixels selected is quite small (say 1 in 64), the apparent average luma of the mask will increase from about 4 to about 20, thus reducing your final result by a factor of 5.
So replacing
255 / AverageLuma(mymask.ConvertToYV12)
by
255 / AverageLuma(mymask.ConvertToYV12(matrix="PC.601"))
should give you the results you expect.
zee944
2nd March 2011, 19:55
How fool I am! I've only tried out your Layer() suggestion, and not the matrix conversion, since I also thought that wouldn't affect the results much. But with matrix="PC.601", it indeed works fine now.
I've already did the color corrections manually (stupid me), but it'll be probably useful later. Thanks! :)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.