Help with difference key technique

johnmeyer wrote on 3/2/2006, 8:23 AM
I thought I knew how to do this, but I'm having a brain freeze.

A client sent me a video of him performing in front of a blank backdrop. Camera locked down, lighting and exposure constant. I have video of the scene before he enters.

I thought there was a way, using a difference mask, to key out the background, in the same manner as I would with a chroma key. I've got the "two cats" demo project files, and it sort of hints at this possibility, but I'm being really stupid here and am not able to figure it out.

Is there a tutorial or project file somewhere that illustrates how to do this? I realize that the key isn't going to be as good as a chroma key and that I'll probably need to use some garbage mattes to fix things up, but I was just looking for a starting point.

Thanks!

Comments

johnmeyer wrote on 3/2/2006, 11:10 AM
Wow! Thanks to you both. This is indeed more complicated than I thought. I've read both the explanations, downloaded the VEG files, and am trying to duplicate, from scratch, in my own project. No luck so far. I can copy my media files to "Problem Solved" and they work, but I think I'm missing one critical setting that allows the background (the gradient media, in your example) to show through.

Don't worry, I'll figure it out, now that I have the VEG file. It's basically what I was trying to do: generate a mask by converting a narrow range of luma differences into a B&W mask that then controls the lower track.

The other thing I would never have thought of was using the Median filters to clean up the mask. I've got to scratch my head about that one.

Anyway, no need to respond further at this point.

BTW, this is for a friend who wants to surprise his wife on her birthday. It's a long series of tributes, culminating with him doing an "American Idol" bit where he sings "happy birthday" intercut with the judges dissing him. He owns the American Idol DVD (which he sent to me) and is doing it for his family at home, so I figured we were OK on copyrights. He sent the media FedEx on Tuesday and needed the results on Wednesday, so I didn't have time to do this final bit of actually putting him into the AI set. However, I'd like to be able to do it the next time, so I'm putting in an hour or so to see what's involved.

[Edit] I went back and re-read the post back in your original thread. This is where you posted your "aha!" moment: Aha!. You mentioned the triangles in your post above, but I didn't read carefully enough. Boy, I thought I knew a lot about this program, but that completely escaped me. Now I have to go back and read the manual to fully understand what these do.

Grazie wrote on 3/2/2006, 12:05 PM

Ah yes! Then pesky triangles . . oh yes . .. .

Once you've "discovered" them you don't forget. And the latest thread about this made us all jump.

Grazie
johnmeyer wrote on 3/2/2006, 12:41 PM
Using this technique, some of the frames still have a little of the original background spilling through. It seems like I should be able to somehow "add" to the mask that is being generated by adding a bezier mask for a few frames, but I can't seem to figure out where to add such a mask. As soon as I add the mask, it seems to "take over" and ignore the mask generated through the difference mask.

It seems like there must be some way to create a garbage mask. I've studied the "two cats" VEG file, and once again must be missing something subtle.

[Edit] OK, it looks like all I have to do is put a duplicate of the background video on the very top track and then put the Bezier garbage mask on that. This overrides the mask that's automatically generated by the difference function so I can force the background to appear. And, to get the inverse of this where I can stop the occasional bleed through of the background where I don't want it, I just put a duplicate of the foreground video and use a garbage Bezier mask on that, where needed. Problem solved.
FrigidNDEditing wrote on 3/2/2006, 4:15 PM
EUREKA!!! - HE'S GOT IT!!! ;-)

I've been thinking about putting together a tutorial on this that is easier for folks like me to understand, just haven't gotten aroudn to it yet. Anyway - glad you got it figured out.

I'll expect the check in the mail within the next 30 days - ohh... couple hundred should do it =P

Dave
DrLumen wrote on 3/2/2006, 5:57 PM
Stated in another way....

In essence, you are doing an exclusive-or (XOR, Difference in Vegas) with the background and the live action video. Do a threshold effect on that result to make the difference "noise" into a pseudo solid mask and then use that mask to drop the live action into another background or vice-versa.

Granted it seems complicated but the principles are actually very simple.

intel i-4790k / Asus Z97 Pro / 32GB Crucial RAM / Nvidia GTX 560Ti / 500GB Samsung SSD / 256 GB Samsung SSD / 2-WDC 4TB Black HDD's / 2-WDC 1TB HDD's / 2-HP 23" Monitors / Various MIDI gear, controllers and audio interfaces

johnmeyer wrote on 3/2/2006, 6:20 PM
The scary thing is, I actually understood that last post.

Yes, the idea is simple, but the things I found difficult were:

1. You need to make the mask track a child of a master blank track. This is probably the least intuitive part of it (for me).

2. You need to have someone give you the secret handshake that involves pointing the arrows on the track fX in the other direction. Normally these are used to determine if the fX happens before or after pan/crop (when used in an event), but on a track, they have a different function, which even now that I know where to look, isn't documented very well.

The garbage masks were pretty simple to figure out -- I really shouldn't have had to ask. However, this is the first time I've really had to use the masking tool for any serious work. The UI is pretty tough. You add points, and then you have to go to the toolbar to change tools so you can adjust their position. The Bezier curve controls are the devil to get hold of (I've been using Bezier tools since the first version of Corel Draw back in the mid-1980s, so I have a fairly good idea of how to use them).

Now I wish I had set up my other computers for network rendering (I have them all set for Vegas 5, but this is one of the few projects I've done in Vegas 6). This is the perfect job for it: 40 seconds of video that's going to take two hours to render. Oh well, another little chore for another time ...

Oh, did I remember to thank everyone? Thanks!!
farss wrote on 3/2/2006, 11:06 PM
I suspect that a difference mask should work better than a CK, it can cope quite happily with a badly lit screen and the other possibility is being able to extract just a shadow for a realistic composite.

If you look at 2 Cats you'll notice a number of additional FXs used to smooth things out, probably to cope with the color sampling of DV25. Also there's a comment about reampling the background plate to reduce the noise level in it to get a better result, might help in this case.

Bob.
johnmeyer wrote on 3/2/2006, 11:15 PM
Yeah, I should go back and look at that tutorial. Now that I've done it for real, all those hints will make a lot more sense.

Now I'm wondering if there is a way to improve the mask by sensing motion between frames. One problem with the difference mask is that if the foreground object happens to have a pixel that is close in value to the background, bad things happen. However, if there was a way to sense movement from one frame to the next, the mask decision could be overridden. May not be possible in Vegas, although I'm trying to figure out if I might get somewhere putting the same media on two tracks, and then offsetting by one frame.

I also plan to spend a little more time figuring out how Vegas computes the "difference" when you select that option. Might there be a way, possibly through a plugin (Wax?) that the difference could be more specifically defined?

Finally, something I didn't figure out until too late was that I could keyframe all the fX that make up the difference mask, rather than relying entirely on garbage masks, to fix up areas where the difference mask fails. Drawing Bezier masks frame by frame, even if it doesn't have to be done as accurately as in rotoscoping, is something to be avoided.

DrLumen wrote on 3/2/2006, 11:28 PM
It's been my experience that shadows on the background do not translate well. The threshold effect used to make the mask eliminates the greyscale, if you will, which would compose the shadow. As a shadow on a background would be transparent, albeit a darker color, the threshold method effectively kills it.

I'm not saying it couldn't be done, possibly with multiple difference masks or some other method, but it would be tough with a difference mask. Personally, I never could muster that much patience. :-)

Maybe an easier way would be to create a duplicate of the mask layer and offset it to look like a shadow. Then, use a solid black layer and vary the transparency to simulate a shadow - like a graphic program would do. One could then feather the object edges (gaussian blur the shadow mask) as needed to get the desired effect.. The use of this method would likely have very limited uses though.

intel i-4790k / Asus Z97 Pro / 32GB Crucial RAM / Nvidia GTX 560Ti / 500GB Samsung SSD / 256 GB Samsung SSD / 2-WDC 4TB Black HDD's / 2-WDC 1TB HDD's / 2-HP 23" Monitors / Various MIDI gear, controllers and audio interfaces

johnmeyer wrote on 3/2/2006, 11:37 PM
Actually, this method worked pretty darn well. The shadows weren't the problem. The real problem in my little project was that the client submitted video that had been taken with the auto-exposure enabled. As the talent moved forward and backwards, the exposure adjusted, and that changed the values of the background, making the difference mask "think" that something was in the foreground.

I don't have any practical experience with chroma key, but I've read the tutorials and seen the problems getting a clean key with DV. I was therefore pretty amazed at how clean these keys could be.
DrLumen wrote on 3/2/2006, 11:41 PM
I haven't used Wax so I don't know what feature or advantages it would have. One thing to consider though is that you can vary the brightness and contrast of the image(s) before the difference is calculated. You should be able to get sharper/softer edges around the subject. It depends on the amount of initial contrast between subject and background.

ie. if you can adjust the BCI to blow out the subject, you may get better results..

intel i-4790k / Asus Z97 Pro / 32GB Crucial RAM / Nvidia GTX 560Ti / 500GB Samsung SSD / 256 GB Samsung SSD / 2-WDC 4TB Black HDD's / 2-WDC 1TB HDD's / 2-HP 23" Monitors / Various MIDI gear, controllers and audio interfaces

johnmeyer wrote on 3/3/2006, 10:47 AM
One thing to consider though is that you can vary the brightness and contrast of the image(s) before the difference is calculated.

Yes, this is a very intriguing idea. The projects that I used as a starting point (provided -- thank you -- by FrigidNDEditing) already took a small step in this direction by using the Black and White converter to force the mask to look at luma values only. The ideal would be to look at each fX and think about what it could do to improve the reliability and clarity of the mask.