Log in

View Full Version : Does layer/mask work?


droolian01
23rd September 2002, 11:12
Hello there.

Sorry for the provocative thread title but i really can't find what i,ve done wrong.
This script first labels the base clip 'base', then makes the overlay clip 'sverlay' which for test purposes is just a white screen. The 'maskclip' is a black and white mask where any pixel that is less than '10' is shown as white, any pixel >=11 is shown as black. This is then applied to 'overlay' with the mask command. The result of layer ('final') should be that where the 'maskclip' is black the 'base' clip should be visible and where the 'maskclip' is white the 'overlay' (which in this case is white for test purposes) should be visible. Heres the script -

converttoyuy2()
Telecide(blend=false)
ConvertToRGB32()

crop(4,4,360,568)

base=Lanczos3Resize(512,384)

overlay=levels(base,0,1,255,254,255)

mask_clip=levels(greyscale(base),10,1,11,255,0)

Mask(overlay,mask_clip)

final=layer(overlay,base,"add",255,0,0,0)

return final


I have tried several combinations of the layer parameters, swaping 'overlay' and 'base' etc...
Also the RESTMASK command does not seem to work. I am using avisynth version 2.0.5 22aug2002. I've attached some screenshots of 'base' 'overlay' etc..

Hopefully someone can figure out what i've done wrong or if the stuff is broken - thanks.

Wilbert
23rd September 2002, 11:23
Maybe it was just a typo, but try this:

...
base=Lanczos3Resize(512,384)
overlay=levels(base,0,1,255,254,255)
mask_clip=levels(greyscale(base),10,1,11,255,0)
clip=Mask(overlay,mask_clip)
clip.layer(overlay,"add",255,0,0,0)

droolian01
23rd September 2002, 11:45
Hi there, thanks for your quick reply!

I just copy/pasted the script you supplied into my avs (after commenting out the old stuff!!!) but unfortunately the output in vdub is just a white screen. It seems to me that the data in 'mask_clip' is not being applied to the alpha channel of 'overlay' by the clip=Mask(overlay,mask_clip) command. Its acting as if the alpha channel is all white/255. Changing the strength setting from 255 to 0 still produces a shite screen.

I just don't get whats going on? I was hoping it was just my script but i think it may be broken:eek:

Thanks again

Didée
23rd September 2002, 11:47
I have struggled some fights with "layer", too ...
Lately, with another fresh attempt, it ran "out-of-the-box", without any problems.
I was using the latest AviSynth 2.05+ (19092002, if I remember right).
The latest snapshot can always be found here:
http://cultact-server.novi.dk/kpo/avisynth/avs_cvs.html

droolian01
23rd September 2002, 12:37
I installed the latest avisynth 2.05+ after first uninstalling the old one with the supplied uninstaller, put new avisynth.dll into system32 folder and ran install.exe - version still gives 2.0.5 22aug2002 - is this right as i know that new/development builds sometimes have the old 'version' infomation in them.

But still no luck, still as described as above:confused:

sh0dan
23rd September 2002, 12:45
Perhaps I'm wrong, but I think you should use RGB32 for all your clips, for transparency to work.

Use convertorgb32() instead.

droolian01
23rd September 2002, 13:05
Hi again.

I did use ConvertToRGB32() -(imediately after telecide in my first post). I just tried -

return messageclip(string(isrgb(overlay)))

as the last line in my script and it came back 'true' unfortuneatly there is no 'isrgb32()' command.

Still very foxed:confused: :confused: :confused:

droolian01
23rd September 2002, 13:24
I've just tried this addition to the script as my mask values may not be 0 or 255 -

bigblack=BlankClip(framecount(base),512,384,"rgb32",25,1,44100,true,true,$000000)
bigwhite=BlankClip(framecount(base),512,384,"rgb32",25,1,44100,true,true,$FFFFFF)

Mask(overlay,bigwhite) or
Mask(overlay,bigblack)

produces the same result. It should switch between base and overlay if it is working correctly.

droolian01
23rd September 2002, 13:44
I've had another (terrifying!) thought. The mask_clip in MASK(clip,mask_clip) must also be in rgb32 format or else you get an error 'souces must be in rgb32'. Now what is the effect of the alpha channel of mask_clip on itself? This is the start of an infinite regress nightmare!!!!
I would have thought that the format of mask_clip should be straight rgb24 as it is essentially on or off.

Am i being silly now?:)

droolian01
23rd September 2002, 15:43
:stupid: :stupid:

Sorry for wasting everyones time, i've solved my problem!!!

converttoyuy2()
Telecide(blend=false)
ConvertToRGB32()
crop(4,4,360,568)
base=Lanczos3Resize(512,384)
overlay=levels(base,0,1,255,254,255)
overlay=resetmask(overlay)
mask_clip=levels(greyscale(base),10,1,11,255,0)

overlay_clip=Mask(overlay,mask_clip)

final=layer(base,overlay_clip,"add",255,0,0,0)
return final

seems that you can't have

mast(clip,maskclip) but must have

clip=mast(clip,maskclip)

Like Wilbert suggested! Although it works in my original script (can't get my head around expression.function.whatever!!)

Phew!

WarpEnterprises
23rd September 2002, 16:02
The main error of the first clip is that:

Layer(base_clip, overlay_clip, string "op", int "level", int "x", int "y", int "threshold", bool "use_chroma")

overlay is the SECOND argument and this is the clip from which the mask is evaluated.

And for understanding don't use the implicit Last variable, at least don't use it with functions with 2 clip args.

As you saw:
Mask(clip, maskclip) is
Last = Mask(clip, maskclip) !!