Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.


Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Thread Tools Search this Thread Display Modes
Old 4th February 2011, 20:56   #1  |  Link
Registered User
Join Date: Apr 2007
Posts: 240
Question about using "summing" masks (for ColorKeyMask use)

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.
zee944 is offline   Reply With Quote
Old 4th February 2011, 21:20   #2  |  Link
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,394
ScriptClip, FrameEvaluate et al, and sum the masks up with e.g. mt_logic("max").
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 4th February 2011, 23:12   #3  |  Link
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,412
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()
  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:
Originally Posted by zee944 View Post
... 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
  for (frame=9914, 10017) {
    m = Trim(frame, -1).Mask(m).ColorKeyMask($F1791A, 12).ShowAlpha()
ApplyRange(9914, 10017, "Mask", m.Loop(10017-9914+1))
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 5th February 2011 at 16:56. Reason: Added missing calls to ShowAlpha()
Gavino is offline   Reply With Quote
Old 7th February 2011, 08:49   #4  |  Link
Registered User
Join Date: Apr 2007
Posts: 240
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...
zee944 is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 03:54.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.