Log in

View Full Version : Using avisynth for green/blue screen matting... mixed results


Mug Funky
24th June 2003, 15:06
hi again to everyone. i've been posting a bit lately, so sorry if that's getting annoying...

my university finally got itself a green screen, so i've been testing it out a tad. i thoght it would be great to write a script to do it for me, because premiere and after effects weren't giving me terrifically good results. so after a few hours playing about and some heavy thinking, i came up with something that works okay.

i'd like to give you some example footage, but i don't think my friend who appears in it would be happy with that :( ... also i'm on a dialup etc...

to test it yourself just chage the avisource bits and use some footage with a lot of bright green in it...

# Load source with green screen visible
clip=avisource("f:\captures\green screen.avi").separatefields()


# Make a blank grey clip to put chroma onto (important for later)
grey=blankclip(clip,color=$808080,pixel_type="yuy2")


# Load up some background footage
base=avisource("c:\ack\uni\clouds.avi").separatefields()


# make chroma only clip, kill all but green, turn it into a b/w clip good as an alpha
# you will need to play with the levels on the end of this to change tolerances.
mymask=mergechroma(grey,clip).converttorgb32().rgbadjust(0,1,0,0).greyscale().levels(94,.5,76,0,255).convertbacktoyuy2().SpatialSoften(1,128,128).converttorgb32()


# convert the original clip to RGB32 so it can have an alpha attached
rgbclip=clip.converttorgb32()


# Attach the alpha to the source clip in rgb32
goodclip=mask(rgbclip,mymask)


# Overlay the clips.
layer(base,goodclip, level=255, op="add").convertbacktoyuy2()#.bob().bicubicresize(384,288,.333,.333)


# Merge fields into interlaced frames again
weave()



NOW... one thing i'd like to be able to do here is have a way to isolate one colour channel as a greyscale clip (like in photoshop, you can select one channel and copy it as greyscale).

that way i'd be able to get a LOT more tonal range to play with when matting.

another thing that'd be awesome is for this to be automated into a single filter with the same flexibility. (here's where i wish i knew C++).

any thoughts?

Wilbert
24th June 2003, 16:07
Did you try ColorKeyMask?

At the bottom of: http://www.avisynth.org/index.php?page=Layer

Mug Funky
24th June 2003, 17:02
yeah. colorkeymask only gives to a threshold. my method gives you a proper greyscale alpha channel, with shades and stuff.

so you don't get that "vanilla ice video" fringe.

you can tweek the levels in the script (but it takes some playing) to change the amount of blur and stuff.

FredThompson
1st July 2003, 20:17
Have you considered putting this on http://www.avisynth.org/index.php?page=ShareFunctions?

What other goodies you got?

Mug Funky
14th July 2003, 05:50
oh, lost this thread for a while... i got an update for this trick after installing avisynth 2.5

works in YV12, but that doesn't make it any faster :( i made use of the VtoY() family of functions... exactly what i needed, almost (it would be AWESOME if these functions worked in yuy2, so i didn't have to upsize the frames to avoid losing fields and stuff)

hope this sparks the whim of a better scritper than me, as i'm sure there's a better way to do this...


# Load source with green screen visible,
# and convert to planar format without killing off fields
clip=avisource("f:\captures\green screen.avi").assumeframebased().pointresize(720,1152).converttoyv12()

# Load up some background footage
base=avisource("f:\captures\stuff.avi").converttorgb()

mymask=clip.VtoY().separatefields().converttoyuy2().temporalsoften(5,2,0).greyscale().levels(102,1,125,0,255).bilinearresize(720,288).weave().converttorgb32()

rgbclip=clip.converttoyuy2().pointresize(720,576).greyscale().converttorgb()# adjust colours here...


# Attach the alpha to the source clip in rgb32
goodclip=mask(rgbclip,mymask)


# Overlay the clips.
layer(base,goodclip, level=255, op="add").converttoyuy2()


okay, now if the source is really clean, then you wont need the temporal soften stuff. however, i've noticed that this script (and it's predecessor, actually) REALLY highlight the differences between a good DV codec and a bad one... my conclusion is that most of them are bad, seeing as this script makes use of colour channels in a critical way.

of the codecs i've tried with this, Pinnacle DV25 is the best, but also the slowest (by a fair amount). both Canopus CDVC and Mainconcept have a chroma upsampling bug that can't be fixed with fixbrokenchromaupsampling(). also, they perform some levels filter that uselessly scales from TV range to screen ranges... so i lose my super-white range.

i'm going to look for some faster codecs that perform as well as pinnacle (it decodes in RGB32, which is annoying, considering there are enough colorspace conversions in my script already).

i may just post back here when i get some insights. i'll also post this script on avisynth.org (should have earlier...)

thanks

[edit] eek... i have no idea how to add pages to the avisynth site... somebody else do it :)

video7
25th November 2007, 21:36
Hello,

I would like that the blue color of my Clip will be transparent.
My code is:

#blaue Maske
maskclip=ColorKeyMask(clip5,$0f0fb4,60)

and after it the blue color turns black.(see pictures after post) If I try mask=ShowAlpha in my overlay avisynth returns an error.Here's my script:

# die Spinne auf der Wand
clip5=AviSource("K:\PIC\projekt Olga\nezue\extras\Spinne\Spinne.avi").ConvertToRGB32()

#blaue Maske
maskclip=ColorKeyMask(clip5,$0f0fb4,60)

# nun overlay auf einen bestimmten bereich anwenden
clip6=ApplyRange(clip1,0,20,"Overlay",clip2,100,5)
# nochmals overlay mit dem zusammengesetztem clip
clip7=ApplyRange(clip6,0,20,"Overlay",clip3,550,5)
# nochmals overlay Vorhänge
clip8=ApplyRange(clip7,170,188,"Overlay",clip4,0,0)
ApplyRange(clip8,170,188,"Overlay",clip5,50,25)

Pictures: http://img403.imageshack.us/img403/4818/spinnesyh5.jpg
http://img410.imageshack.us/img410/3470/spinnebbm6.jpg

Thank You for Your help!
video7