Log in

View Full Version : Question about using "summing" masks (for ColorKeyMask use)


zee944
4th February 2011, 20:56
I'm selecting a movie's credits with ColorKeyMask in a certain frame range. Like this:

lettersmask=ApplyRange(9914, 10017, "ColorKeyMask", $F1791A, 12)

How can I sum ALL the pixels collected through the range and have it as one mask?

The credits are put on a non-constant, live action background, so I have to use a quite low threshold to not select false pixels everywhere on the picture. So the selection is not full on any of the frames, and slightly differs on every frame. But summing up them would result in a near perfect mask. How can I do that? (It'd be even better if I could spread that perfect mask onto the mask clip's (lettersmask) range afterwards, but that's not vital.)

Thanks in advance.

Didée
4th February 2011, 21:20
ScriptClip, FrameEvaluate et al, and sum the masks up with e.g. mt_logic("max").

Gavino
4th February 2011, 23:12
You don't need to use mt_logic, since repeated applications of ColorKeyMask act to sum the mask anyway.
(Also ColorKeymask is an RGB32 filter while mt_logic works on YUV.)

You can use ScriptClip like this:
...
Trim(9914, 10017)
m = ResetMask().ShowAlpha()
ScriptClip("""
m = Mask(m.SelectEvery(1,-1)).ColorKeyMask($F1791A, 12).ShowAlpha()
return m
""")
The result of this script is a clip which accumulates the mask frame by frame, so the mask you actually want is in the last frame. However, you can't extract that frame and use it directly in the same script, as it must be rendered linearly to construct its result.

An alternative is to use GScript to loop explicitly over the required frames.
This has the advantage that you can go on to use the resulting mask in the same script - as you said:
... spread that perfect mask onto the mask clip's (lettersmask) range afterwards
Here's how:
...
m = ResetMask().ShowAlpha().Trim(0,-1) # 1-frame opaque mask
GScript("""
for (frame=9914, 10017) {
m = Trim(frame, -1).Mask(m).ColorKeyMask($F1791A, 12).ShowAlpha()
}
""")
ApplyRange(9914, 10017, "Mask", m.Loop(10017-9914+1))

zee944
7th February 2011, 08:49
Thanks, it worked. Although eventually my idea was not proven to be right (the summed mask still wasn't good enough), so I have yet to find another way to select the letters.

GScript - what a tool... :)