View Full Version : Overlay with Mask: how completely remove background
belonesox
4th August 2013, 22:44
I try to build reliable chromakey processing, but have probably have some misunderstandings of Overlay/Mask functions.
For example, let we have background
http://wiki.4intra.net/images/thumb/5/59/Background.svg/256px-Background.svg.png
and try to put on front of it other video
http://wiki.4intra.net/images/thumb/e/e4/Red-circle-on-green.svg/256px-Red-circle-on-green.svg.png,
removing green "chromakey" by code:
function GreenMask(overlayvideo){
mask_hs = overlayvideo.ConvertToYV24().MaskHS(startHue=160, endHue=300, minSat=1, maxSat=149, coring=false).Levels(0, 1, 255, 255, 0)
return mask_hs
}
source_5c3922551b3d12d4 = AVISource("background.avi").Spline64Resize(1200,720)
source_614c8c0fb354420e = AVISource("red-circle-on-green.avi").Spline64Resize(1200,524)
src = source_614c8c0fb354420e
Overlay(source_5c3922551b3d12d4, src, x=60, y=90, mode="blend" , mask=src.GreenMask() )
(All test files can be downloaded (https://www.dropbox.com/sh/8c3jy7dvnig111w/xL0dpMO7NC))
But I can not completely remove green background:
http://wiki.4intra.net/images/thumb/7/7a/Wtf-is-rectangle-with-mask-overlay.png/512px-Wtf-is-rectangle-with-mask-overlay.png
What is wrong with my AVS-code?
IanB
4th August 2013, 23:20
....coring=false).Levels(0, 1, 255, 255, 0, coring=false)
But you would be better to use Invert() to flip the values.
belonesox
5th August 2013, 09:58
....coring=false).Levels(0, 1, 255, 255, 0, coring=false)
But you would be better to use Invert() to flip the values.
Thank you very much!
I did not use Invert, because I try to made educational webinars (like "talking heads over screen") and I have two problems, that I try to solve by adding some transparency to "talking heads"
.Levels(0, 1, 255, ***220***, 0, coring=false)
* First problem — make screen readable under talking head.
Some of such webinars with AVS chromakeying (https://vimeo.com/album/2361790) for example (it is vimeo, possible to start video from any moment, so dont listen all, just pick some random moment).
* Second — I have classical problem with "chromakey, fringing/stepping edges, especially from DV" and I now have no idea, how to do this right with AVIsynth (not Adobe Premier). Blurs? several overlays with different transparency?…. Adding some transparency hide this problem a little.
If anyone have good idea, how to do it (edges problem with chromakey) right, or just OK, I will be very happy!
poisondeathray
5th August 2013, 16:27
* Second — I have classical problem with "chromakey, fringing/stepping edges, especially from DV" and I now have no idea, how to do this right with AVIsynth (not Adobe Premier). Blurs? several overlays with different transparency?…. Adding some transparency hide this problem a little.
If anyone have good idea, how to do it (edges problem with chromakey) right, or just OK, I will be very happy!
Don't use crappy DV ! :D . Shoot progressive . Even camera phones shoot better quality than DV these days
Work on your lighting. Read up on chroma key setup. Lighting is probably the most important for keying
For DV:
Use a good deinterlacer like QTGMC before keying.
And the old technique people used to use was to blur the chroma channels
belonesox
5th August 2013, 23:07
Don't use crappy DV ! :D . Shoot progressive . Even camera phones shoot better quality than DV these days
OK, I will. Actually, I use a pack of Panasonic GS400, which was usable because it possible to simultaneusly stream (dvgrab->ffmpeg->rtmp) and record AVISynth-friendly AVI files (not MTS, etc), and have 3CCD 1/4" matrix.
Work on your lighting. Read up on chroma key setup. Lighting is probably the most important for keying
I know. But unfortunately I cant do good conditions (no room, no place, lost my light and umbrella), but I dont want ideal VFX like "Life of Pi".
I just want to do maximum that can be automated by AVISynth or plugins, and some heuristics to fix (blur, etc) fringed edges are very welcomed.
For DV:
Use a good deinterlacer like QTGMC before keying.
OK, I will try. I used SmoothDeinterlace, but in future I will shoot chromakey in progressive.
And the old technique people used to use was to blur the chroma channels
But how? Blur chroma channel on the frame with chromakey before overlay?
Or blur frame for getting (by MaskHS) more stable mask?
May be you can provide couple of lines with pseudocode?
Thanks all in advance.
IanB
6th August 2013, 00:07
You are experiencing the issues of sub-sampled chroma. A blind ConvertToYV24() just does a BicubicResize(b=1/3., c=1/3.) of the chroma planes assuming MPEG2 chroma location.
If you are using DV you need to appreciate the chroma resolution and positioning very carefully.
For PAL it is 360 x 288 with the R-Y samples located on the even lines (0, 2, 4, ...) and the B-Y samples located on the odd lines (1, 3, 5, ...). Within a line the chroma samples are located on the left even pixels (0, 2, 4, ...). And then there is interlacing.
For NTSC it is 180 x 480 with the chroma samples on every lines, but only located on every 4th pixel (0, 4, 8, ...) within a line.
You need to be aware of how your work flow delivers raw DV data into your input format (YV12, RGB24, etc). Ideally you can get the raw data and process it in a meaningful way to maximise plane alignment.
You might be able to improve the edges of your mask by modulating with the luma plane data in the edge region.
Use something like "Interleave(ConvertToY8(), UToY8(), VToY8() )" on your mask clip to carefully inspect how the 3 planes are aligned and interact before you extract the final mask.
A surprisingly effective approach, if your content is suitable, is to just sub-sample the luma plane to match the chroma, especially when you are downsizing a talking head.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.