PDA

View Full Version : Static mask - how ?


Shubin
6th October 2007, 19:33
I've read all things about masks in masktools and avisynth doc, and I think (maybe I'm wrong here) that only moving masks are supported. But I need a static mask.

What's the difference ?

In moving mask you have an overlay clip that contains some areas that should be removed. This is done with a mask. What is masked, is not visible. The mask is "tied" to an overlay clip.

In static mask you have a base clip and want to replace some areas of it with an overlay clip. In this case the mask is "tied" to the base clip. An example is usually seen in 50-s films : when the car is moving, the view from the window changes, but it is visible that it is another movie overlayed on first one.

Technically I have a clip and want to replace some areas of it, calculated using the clip colors, with contents of another clip which has different size and typically will move around.

How can I do it ? Should I write another plugin ?

foxyshadis
7th October 2007, 01:11
A truly static mask can be inserted with imagesource("").converttoyv12(matrix="pc.601"), if you have it in a png or whatever. If you're bluescreening, ColorKeyMask might be what you need. If you have more complex needs, you might need a lut or even a custom plugin.

IanB
7th October 2007, 01:15
A static mask is fixed for all frames in the clip, typically you provide it in a single image file (.bmp, .png, etc).

A moving mask has a unique mask for each frame in the clip, it will be a separate clip in it's own right. The degenerate case is that all the frames are the same, i.e. it reverts to being a static mask.

These should not be confused with a motion mask which is used to select areas in a frame that are different from related areas in adjacent frames.

To turn a single frame clip into many frames use "Loop(n)".

To freeze 1 frame in a clip to many frames use "FreezeFrame(n, start, end)"

To build a mask clip to track an area of a particular colour use "ColorKeyMask".

MaskTools has many other features to manipulate masks and images in advance of the limited tools native to avisynth.

Shubin
7th October 2007, 08:58
Yes, I understand this. I've made a static mask from the png picture and Loop() already. But the problem remains. Using Overlay function I can apply mask to the OVERLAY clip, but I need to apply it to the BASE clip. I cannot simply exchange clips, because the ovrlay clip should move relative to base clip and the mask.

What I need is to "cut a window" in a base clip and see moving overlay clip through it.

foxyshadis
7th October 2007, 09:38
overlay(base,new,mask) doesn't work? The behavior your describe is exactly what you should be getting, if the mask is working. You can also use mt_merge, which is strictly weighting based on the mask, no fancy blending modes.

As a test, output the mask to be sure that it's actually showing up the way you want it to.

Shubin
7th October 2007, 10:17
overlay(base,new,mask) doesn't work?

No. It says "Mask clip should be the same size as overlay clip". In my case it is the same size as the base clip.

IanB
7th October 2007, 13:14
Sounds like you need to invert your mask. i.e. swap transparent and opaque areas.

Overlay(base, overlay, mask) == Overlay(overlay, base, mask.Invert())

Shubin
7th October 2007, 14:56
Sounds like you need to invert your mask. i.e. swap transparent and opaque areas.


I do not think that it will change its size...

Wilbert
7th October 2007, 16:05
What size is the mask? What size is the overlay-clip? What size is the base-clip?

Shubin
7th October 2007, 19:26
What size is the mask? What size is the overlay-clip? What size is the base-clip?

The size of the mask is exactly the same as the size of the base clip : 720*576. The overlay clip is smaller, 640*480

foxyshadis
7th October 2007, 20:28
Well, I really don't think the error can get much more explicit. Crop your mask down, inside or outside avisynth, to match the overlay instead of the base clip. And if the overlay isn't supposed to start at 0,0 (upper left corner) make sure you use x and y. Alternately, pad/crop/resize your overlay clip to match the base.

Fizick
7th October 2007, 21:57
may be you need not in static but in sliding (tracking feature) mask for base clip?

IanB
7th October 2007, 23:22
:script: and a matching copy of a good example frame from each of the base, overlay and mask. Plus a quick hand painted version of what you expect the output to look like (just use paint?? to paste approximate parts of the overlay onto the base) (highly compressed jpeg will be okay)

Shubin
8th October 2007, 06:18
Here I tried to draw what I want to do. The upper picture shows what I already know how to make - the mask has the same size as an overlay clip, and when the overlay clip moves (using Animate) the mask moves with it.

The lower picture shows what I need. The mask has the same size as the base clip, and always stays at the same place.

IanB
8th October 2007, 08:31
As I said previously you will need to abuse this relationOverlay(base, overlay, mask) == Overlay(overlay, base, mask.Invert())
With a bit of trickery, you extend the Overlay clip enough so you do not clip the original base clip, I chose 100 on all sides but knowing how X and Y vary you can pick better values. Slide the Base clip over the Overlay in the opposite direction. When done crop off the unused bits of the Overlay, I used PointResize to avoid any mod 2 restrictions that a straight crop might have.
...
InvOlay=Base
H=Base.Height()
W=base.Width()
InvMask=Mask.Invert() # Make middle blob transparent
InvBase=Olay.AddBorders(100,100,100,100) # extra room
Overlay(InvBase, InvOlay, 100-X, 100-Y, InvMask)
PointResize(W, H, 100-X, 100-Y, W, H) # Restore base

Shubin
9th October 2007, 06:05
Thank you, IanB, I'll try this