The Basics of Keying



Description:
As I understand them
 

This tutorial is designed as a primer to the basics of keying, or placing selected parts of an image over another one.  It is based on my background in television as a vision switcher, and what knowledge of digital video I’ve picked up over the years.

 

I’ll be starting with the very basics of video signals and luminance values to explain how keying works.  Then I’ll try and explain how it translates into digital signals.  After discussing the arcane study of Alpha Channels and 32 bit graphics, we’ll finish by having a look at how all this can be used to create effects beyond simple titling.

 

One thing before we get started.  I know that for many people these sort of tutorials are boring as batsh*t, and that most inexperienced users just want a simple, straight answer to whatever problem is befouling their editing experience at that moment.  I was the same when I started, so I don’t expect you to be any different.

That said, read this through from start to end.  Digital video is based on the analogue video that went before it so understanding where we’ve come from is essential to knowing where we’re going.

 

If you’re an experienced user and you pick up something I’ve got wrong, or haven’t explained correctly, please let me know.  I’m always willing to learn something new, and even more willing to unlearn something wrong.

 

The Basics of Analogue Video

 

To get the idea of how keying works we have to start at the very basics of the video signal. Now, a standard analogue video signal is pretty weak.  It's only 1 volt of electrical energy which is less than the voltage you get from a standard battery.  This is one of the reasons why it's so easy to introduce noise into an analogue picture.  It doesn't take much interference to upset the apple cart.  But I digress.


If you look at the voltage signal strength as a graph (see figure 1), we'll start to get a feel for what's what in a video signal.  Imagine that you have a white to black gradient as a video frame, white on the left of screen, black on the right of screen (see Figure 2). The white part would be at the top of the graph, or 100% luminance.  The black part would be at the bottom (actually .3 of a volt in analogue, but that's not important here) at 0% and the gradient from white to black would produce a downward sloped line that would join the white to the black as you went across the screen.

That's luminance.  The higher the voltage of the video signal, the whiter the video.

 

  

       

 

Figure 1                                                          Figure 2


Again, things are a little different in the digital domain, because everything becomes pixels with RGB values, but the thought is the same. We’ll look at that further down the track.


Now, to key a picture (key: short for keyhole) the video requires a key signal, or matte shape.  The idea is that a shape is used to "cut a hole" in the picture.  What's happening is that the matte shape is allowing a "window" for the video to show through.  Character generators and chroma keyers will create a black and white matte shape based on which parts of a frame need to be keyed and which parts need to be transparent to cut a hole then fill that hole with its own video fill. Traditionally white means opaque and black means transparent. 


In the old days that was how they put titles on the television.  A graphics artist would produce a black and white graphic and the switcher would key it over whatever picture it needed to go, the video of the graphic acting as both the hole cutter and the video fill (also known as a "self key").  

 



The idea is that anything above a certain luminance would be opaque, and anything below would be transparent.   In the above example if the transparency or “clip” level was set to 50% luminance only anything brighter than that, in this case the white areas of the TITLE card, would be opaque.  The black areas would be completely transparent, allowing just the text to be keyed over the top of the newsreader shot.

 

That’s all well and fine, but eventually a new keying technology came along.  Known as “Linear Keying”, it gave the switcher the opportunity to create different levels of transparency based on the greyscale values of the key signal.  When set to the full range of greyscale anything 100% luminance was completely opaque, 0% luminance was completely transparent, and 50% luminance was semi-transparent.  You may have seen scoreboards and titles on television news and sports where part of the graphic is completely transparent, parts are semi-transparent so part of the background shows through, and some, usually the text, is completely opaque.  That’s linear keying in action.

This means that if you use our white to black gradient shown above and key it over a background picture the white leading edge would be completely opaque, the black edge would be completely transparent, and the gradiating level in the middle would produce a picture that seems to fade away to whatever is underneath it. 

 

 

Now for the fun part.  The nice thing about key shapes is they are not restricted to just keying themselves.  Our white to black gradient is pretty boring by itself, but imagine if we could use its transparency settings and fill it with another piece of video?  Or perhaps some white text on black?  Or an abstract frame shape?  Well that's what's happening with the track matte or image matte transparency options in Premiere, or the Luma Matte in After Effects.  They allow you to take a greyscale image to "create a window" and fill it with whatever you like.  Once you realise the implications of this
the creative possibilities are mind boggling.

 

How this works with Digital signals

 

Still with me?  Good.  You now have a basic understanding of how a key works.  But how does that translate to digital?  Well the basics are pretty similar.  Keys are still based on a greyscale key signal, and luminance percentages play a part, but there are some small differences, chiefly to do with the colour space.

 

Analogue signals are based on electronic waves.  While a video signal is small, only a volt, it can be divided into an almost infinitesimal number of pieces.  You aren’t, for example, limited to whole percentage points.

Digital signals, however, are made up of specific “steps” delineated by the number of 1’s and 0’s that pass by.  In the case of digital video it tends to be 256 steps between complete black and complete white.

 

Standard digital video signals, as used by most of us consumers, prosumers and professionals, are what’s known as “8 bit”.  This can be easily explained by doing a bit of simple mathematics.  A computer “bit” is made up of one of two options due to its binary nature; a 1 or a 0.  So a single bit can have two states.  If you start adding additional “bits” you double the amount of possible options for each one. For example a 2 bit signal can have 4 possible states, i.e. 0:0, 0:1, 1:1 and 1:0.  A 3 bit signal  has twice that number of possible states again, i.e. 0:0:0, 0:0:1, 0:1:0, 1:0:0, 0:1:1, 1:0:1, 1:1:0, 1:1:1.

Mathematically it’s 2^8 or 2x2x2x2x2x2x2x2.  Let’s work it out.  2x2=4. 4x2=8.  8x2=16.  16x2=32.  32x2=64. 64x2=128. 128x2=256.  There’s your 256 possible combinations to make up the luminance scale.  In RGB colour space there’s one 8 bit channel assigned to each of the primary colours of light; Red, Green and Blue.  Maybe you’ve heard of 24 bit video?  That’s where it comes from; 3 x 8 bit channels, one for each of the colours.  Together they make up the full range of available colours for your video. 256 x 256 x 256 = 16 777 216.  That’s the “16.7 million colours” you hear about when you set the export settings in Premiere.
 

In the end though even with all these colours in all their possible combinations you still wind up with only 256 levels of luminance in a 24 bit video signal, which is great if you want the luminance levels of the picture to act as your key signal, but what if you want, for example, to key black or dark colours? This brings us to Alpha Channels and 32 bit graphics.

 

Alpha Channels

Or how I learned to stop worrying and love the greyscale.

 

Bit of background again.  Earlier I explained how the track matte and image matte transparencies allow you to cut a hole using a greyscale image, and fill it with a secondary video source.  Well, this is how Character Generators and Chroma Keyers work.  They have two separate video feeds; the key signal which is a greyscale image, and a composite video signal.  The vision mixing console cuts the hole with the key signal and fills with the video signal.

 

It’s quite possible to use two video sources to key in Premiere as well; one file as the hole cutter and another as the video fill, and use the track matte transparency.  But wouldn’t it be nice if we could keep the key signal and store it somewhere in the file until it’s needed?  That’s what Alpha Channels are for.

 

A graphic or video with an alpha channel is a standard 24 bit file with an additional 8 bit channel.  This is commonly known as a 32 bit file.  This extra channel is specifically designed to hold the file’s transparency information.  This allows you to key low luminance objects without the need for a separate key signal file.  It also allows semi-transparency in a graphic or file by using the range of greyscale as mentioned earlier.

 

Alpha Channels come in two types; straight and premultiplied. 

 

Straight alpha channels are our basic greyscale key signal.  Picture information can exist beyond the edges of the alpha channel, and can look quite messy when viewed like this.  However, when the alpha channel is applied it cuts out just the picture information needed, discarding those rough edges.  The colour channels are unaffected by the transparency settings.

 

Premultiplied alpha channels are a clever mathematical method to attach alpha channels by multiplying the alpha channel information with the colour channels, based on the background the program is using at the time.   If you have a black background, the alpha channel transparency will affect the levels of red green and blue down as transparency increases and more black shows through.  If premultiplied with white, it will push their values up as transparency increases.

 

For a great rundown on Alpha channels, and some of the dilemmas involved in getting them mixed up, I recommend Tech Tip 01 from the CD accompanying Chris and Trish Meyer’s excellent book “Creating Motion Graphics in After Effects”.  Even for non-After Effects users, it runs through some of the basic technical questions, such as fields, interpolation, and different aspect ratios in very easy to understand language.

However, for those that don’t wish to fork out the money I’ve found this particular Tech Tip on the internet.  Someone’s obviously been a bit naughty.

http://www.ledet.com/coolstuff/software/aftereffects/alphachannel.pdf

 

For more technical information on Alpha channels, check out

http://www.micro-intel.com/users/ypoissant/tutorials/Alpha-about.htm

 

What you need to know as Premiere users is this.  Most graphics created in a program like After Effects uses a Straight Alpha channel, and so when you go to key it you want to use the “Alpha Channel” transparency.

Graphics that use a Premultiplied Alpha channel, and depending on whether you are using a black or white background (transparent backgrounds are treated as white), should be keyed using the “Black Alpha matte” or “White Alpha matte” respectively.

 

When will this situation arise?  Well my research on the internet seems to indicate that Photoshop uses Premultiplied Alpha channels, however the Adobe Premiere User Guide (affectionately known as the “f***ing manual”) says quite clearly

 

“Use the Alpha Channel key on clips that contain a straight alpha channel, such as images created in Adobe Photoshop, Adobe Illustrator and After Effects.”

Adobe Premiere 5.0 User Guide, 1998 Adobe Systems Incorporated, p268

 

Adobe made both programs, they should know.

 

Image and Track Mattes and What I Can Do With Them


 Image matte transparency in Premiere uses a matte shape that you choose by selecting it from the little box up in the top left of the transparency box.  If the matte colours are round the wrong way (black where you want it to be opaque and white where you want it to be transparent) you can click the "reverse" checkbox to "invert the key".


Track matte uses a similar idea to image matte, but it takes the luminance values of whatever is in the track directly above it to act as its hole cutter.  As it is a track, it can be manipulated in exactly the same way any other track in Premiere can be, including motion, effects, or, if you use a virtual clip pointing to an earlier composition, transitions.

 

Now to have some fun with them.

 

Try taking white text on black and filling it with some abstract moving video.  Looks a lot better than plain text alone.   For a video tutorial on how to do it, and put what we’ve been discussing into practice, have a look over at Curt Wrigley’s site, in particular the “Video through Title” tutorial.

For a twist, use it as a track matte transparency and try applying filters to the matte clip.  I like the “bevel edges” effect for that faux-depth look, but keyframing blurs or distortions can work as well.

 

Another method involves taking a single, or a series, of matte shapes or text and using either a track matte or image matte transparency to key a piece of video over itself (same piece of video on track 1 and track 2).  If you offset the video tracks from each other in time, a delay appears where the matte is cutting out the top layer.  It’s particularly effective with fast changing matte shapes. 

If that's not to your taste cue them back up and apply an invert and blur filter to the bottom video track.  Now you have the same piece of video, but only the piece showing through the matte looks normal.  You should notice that where the image is grey instead of black or white the two video tracks fade together.


These are two simple, but effective ideas.  The possibilities are limitless.

 

I hope you’ve enjoyed this walk through titles and transparency.  See you in the forums.