3.4 Using Masks
In our previous extended study material Level 3.3 Stabilizing Footage Using Tracking, we covered using the stabilize effect in combination with the tracker panel to remove instability in a clip. Find out more about The Pixel Farm Training Academy and register for the next available class here.
In this tutorial we will be looking at the mask panel and how we can use masks in combination with the effects in our stack.
If you haven’t completed the previous level 3 tutorial, or level 2 training, I would suggest going back and starting from there as some of things we will be covering build on the knowledge we acquired in the previous level.
NOTE: To follow along in this tutorial, you will need access to the clips provided for the class. If you don’t have them to hand, below you will find the link to download the footage again.
To learn this tutorial you will need to download and use the footage below.
01. Mask Panel Overview
In our last tutorial we were looking at clip_003 and corrected the high and low frequency stability issues using the Stabilize effect and Tracker panel, as well as briefly looking at the F-Curve panel. This time we are going to be using another panel called the Mask panel.
Let’s add in an effect into the stack called Video Grade under the Colour Operations. The purpose of adding a Video Grade into the effects stack is so that when we use a mask we can see an obvious change in the cinema and understand how the mask is working.
With Video Grade selected let’s click on the Mask Panel button on the top left. Two panels will appear as soon as we click the button. So what does a mask do? A mask allows us to focus an effect to a specific area that the mask covers. Masks can be activated and deactivated in different effects and can be animated over time.
At the bottom of the UI we have the Mask list where masks can be organised. Currently this is empty as we haven’t created a mask for this clip yet.
To the side we will have the Mask creation panel. When a new mask is created, it will be added to the Mask List, and activated in the current effect (unless the mask is created in the base clip, in which case it will not be activated).
To the right of Mask list we have mask editor and mask tracking panel. Allowing us to adjust the edges of our masks and animate them using PFClean’s tracker. You will notice as we have not created a mask yet these options will be greyed out.
02. Creating a Mask
In the mask creation panel there are a number of options available to us so let’s go through each one and how we use them before we create a mask.
(Bezier Roto): to create a Bezier roto-spline. Click with left mouse button to place roto vertices in Cinema. Dragging the mouse whilst placing a vertex will expose Bezier handles, and releasing the mouse button will place the handles. After placing all vertices, click on first vertex to close the roto-spline and generate the mask. You might use this for creating a mask for areas of the frame where more precision masking is needed as well as areas with hard edges and angles.
(X-Spline mask): to create an X-Spline mask. Click the X-Spline button and then click with the left mouse button in the main image window to place vertices. To close the mask, click on the first vertex again. X-Spline handles are available to control the tension and thickness at each control point. X-Splines can be useful when creating tight masks around people.
(Colour Roto): to create a colour-based roto mask. These are different from normal roto masks because they use colour information to estimate the correct mask value at each pixel between the inner and outer boundary edges. These can be used to quickly construct a mask around the edge of an object without the need to carefully animate the mask boundary in each frame.
(Colour Selection mask): to create a selection mask that can be used to identify a coloured region. The spatial and colour support of the mask can be adjusted interactively in the cinema window. For example this could be used to generate a mask for a blue sky.
(Rectangle): to create a rectangular mask. Click with left button and drag the mouse to place the rectangle. Once the mouse is released, the rectangle will be converted into a roto-spline to generate the mask.
(Ellipse): to create an elliptical mask. Click with left button and drag the mouse to place the ellipse. Once the mouse is released, the ellipse will be converted into a roto-spline to generate the mask.
(Lasso): to create a lasso mask. Click with left button and drag the mouse to draw a lasso. Once the mouse is released, the lasso will be converted into a roto-spline to generate the mask. This can be a great way to create a quick roto of an area without having to click and create each point.
Okay so now we know what masking options we have available to us let’s create our first mask. For this tutorial I am going to create a Bezier roto. Click on the Bez button to begin creating your mask. When you do you will notice it is highlighted in blue and will remain so until you have completed your roto. When you click to make your first bezier point don’t forget to click and drag the first mouse button.
I have created a sausage shape covering the mid part of the clip. If you intend to animate your roto try not to create too many bezier points, less is always more, too many points and too many keyframes can lead to matte boil in your footage. When I created this roto I accidently added in one too many bezier points. To delete a single bezier point move your cursor over the point and click the second mouse button, then select delete. When our mask is complete you will see the mask in the list at the bottom, its default name will be Roto0001 before we take a closer look at the mask list and the other settings lets see what the mask does.
Now that we have created a mask let’s now go back to the Video Grade and see what happens when modify the parameters. We can do this by clicking the Mask Panel button again. When we deselect the Mask Panel we will still see the outline of the mask but the center is no longer filled in. Let’s go ahead and change the Gamma in the Video Grade effect. When changing the gamma in the Video Grade effect, we can see the result of the change is confined to just the area of the mask rather than the whole frame.
Let’s click the reset button on the Video Grade effect and re-open the Mask Panel.
03. The Mask List
In the mask list we can see our bezier roto we can change the name of our mask by double clicking on the name Roto0001, let’s rename this mask to parent. We can also change the colour of the outside line of the mask by clicking in the square in the Col column, the default is white. Changing the mask edge colour might be useful if you are working against a bright background. Next to the Colour column we have the frame range this tells us the active frame range of the mask.
Over on the right panel click the button. Once we have done so you will now see that any effect we have attached will now be confined to the area outside of the mask. We can see by the Yes in the column that the mask has been inverted. Let’s now set this back to normal with no inversion by clicking the Invert Mask button again.
Moving onto the next column we have the Boolean operations. This option will only become available if the Mask has a Child Mask, with the parent mask selected in the list go ahead and create a new rectangle mask by clicking on the Rect button and drawing a rectangle over the edge of the parent mask. Once created rename your new mask to child. Currently we can only see the child mask in the cinema, if you click back to the parent mask you will now see both masks together.
When creating a new mask, if a mask is already selected, the new mask will be added as a child. Child masks can have boolean operations associated with them which affect the way they combine with their parent. Note that only one level of child masks can be created: it is not possible to add a child mask to another child mask.
If we had not selected the parent mask before hand and created an entirely separate mask we would only be able to use one or the other with the current effect. Child masks are especially useful when doing full body roto, this way we can break the roto up into simple geometry for each of the body parts and in addition use tracking to reduce the amount of animating we have to do. We will be covering tracking and masks in a bit later.
Let’s now have a look at the Boolean functions and see the effect they have on the masks. Click on the child mask and now second mouse click on the Add in the Boolean column.
We can see there are four settings in total, the default being Add which adds the child mask to the parent. Subtract will remove the child mask from the parent. Intersect will leave a mask just where both masks overlap. Finally Exclude will leave a hole where both masks overlap. Let’s leave the mask on the Add operation for now.
Next to the Boolean column we have the Tracker column. This is where we can assign Tracker we have created to a mask.
Making sure we have the parent mask selected, second mouse click in the Tracker column where it says None. You will see a list of all the trackers we created for the previous tutorial. If we select one of the trackers it will use the tracked movement in clip and apply it to the mask. We will be looking at using a tracker with a mask in another shot.
Next to the Tracker column we have A (active) column. This is where we can switch on or switch off a mask. A mask is on when there is an X in the column.
Finally on the we have the Effects column. This tells us which effect the mask is attached too. We can use the same mask for multiple effects. I have added a regrain into the effects stack as an example. When you first load the Mask Panel with the Re-Grain effect the masks will be greyed out. All we need to do to use the same mask again is click in the Active (A) column to switch the mask on. The mask can also be switched off in the same way. We can now see in the Effects column the mask is attached to both Re-Grain and Video Grade. Any changes or editing to the mask we make now will apply to both effects.
04. Editing the Mask
Let’s now look at the last column in the Mask Panel.
If we have used a spline based mask in our clip like we have you can insert additional points into the mask by clicking on the button and clicking on the edge of your mask. Once you are done adding new points in, simply click the button again. You can change your newly inserted points into bezier points by clicking the second mouse button and unticking Linear in the mini menu.
If we need to reposition the entire mask rather than just individual points we can pressing and holding ‘J‘ on the keyboard. To move the mask entirely, click and drag inside the transform tool with the left mouse button. Individual corners of the transform tool can also be adjusted, and masks can be rotated using the central rotate handle. The axis of rotation can also be adjusted. Releasing ‘J‘ will remove the transform tool from the Cinema.
Clicking the Edit Inner and Edit Outer buttons will allow the vertices on the inner and outer boundaries to be edited. Click and drag a vertex with the left mouse button to change its position. Edges can be adjusted as well as vertices by clicking and dragging with the left mouse button. Holding the Command key whilst clicking and dragging with the left mouse button will allow multiple vertices to be selected at the same time. When several vertices are selected, they can be adjusted together using the left mouse button. Click outside the mask whilst holding Command to de-select all vertices.
The Thickness edit box can be used to change the thickness of the gap between the inner and outer mask boundaries (by default, this is zero for everything except for colour-based roto masks) and create a soft-edged mask.
The final column is for tracking which we shall be moving onto next.
05. Using a Tracker with a Mask
Let’s look at a different clip now. We are going to go back to the Workflow Manager and click on the Workbench with the filtered 2K overscan shots in. In the Workbench we are going to select the third shot along in the Worklist with the blue background and the character holding out his hands. Once selected we are going to add a Dustbust effect under the Repair Operations to the effects stack. We are going to take a look at two different ways of using tracking with masks.
Let’s select the Tracker Panel on the top left like we did in the previous tutorial. We are going to be placing a tracker over the characters face so that we can use the tracker in combination with a mask.
I have placed the tracker where the characters teeth are and left all the other settings at default. The one thing I will do is rename the tracker from Tracker0001 to face_track, renaming is useful if you have lots of trackers in your clip. I tend to name my trackers with the location they are tracking. If you haven’t completed the previous tutorial on tracking I recommend going back and doing that one first.
Once we have positioned the tracker let’s go ahead and click the track forwards button. Once the tracking is complete we are going to open up the Mask Panel, making sure we are on the first frame click the create Bezier button and draw a mask around the characters face.
Now that we have created our mask we can attach our tracker to it in the mask list by clicking the second mouse button in the Tracker column and selecting it from the list.
We can now see face_track is attached to Roto0001 in the mask list. Let’s step through the clip using either the right or left arrow keys on the keyboard. What you will see is the mask uses the tracking information and is now animated and following the characters face.
Animating the mask doesn’t have to end there. If we go to the last frame of the shot we can see where the character has rotated his head the mask now doesn’t quite cover his face. Pressing the ‘J‘ on the keyboard click inside the mask and drag it back into position. This has inserted a keyframe. We can insert multiple keyframes across the clip if we needed to, as well as keyframing individual vertices.
Let’s go to the middle of the clip around frame 38 and adjust a single vertex under his chin and drag it down almost to his finger, it’s extreme but will demonstrate how the vertices animate over a number of frames. Now let’s step towards the end of the shot. You can see the vertex moving back towards the position we had set on the last frame.
In the timeline we can also see a keyframe has been set on frame 38 represented by a yellow marker. We can remove keyframes using the following buttons.
The R-, Remove Key, and R+ buttons can be used to remove vertex keyframe positions from the mask. Clicking R- will remove all earlier keyframes, and R+ will remove all later keyframes. Clicking Remove Key will remove keyframes at the current frame only.
The K- and K+ buttons can be used to quickly move to the previous or next frame that contains a keyed vertex.
Let’s now look at the other way of tracking our shot, let’s delete our mask using the Del button in the bottom right of the mask list as we will not be need to use it again.
This time we are going to create the same mask over the characters face again but we are going to be tracking the mask inside of the tracking panel. Again making sure we are on the first frame of the clip, click on the Create Bez button to begin creating a bezier mask. Draw roughly the same mask as we did before.
Masks can be tracked throughout the clip using the controls described below. Note that the mask transformation obtained by tracking is independent of that produced by keyframing vertex positions. This means a mask can be tracked and then its vertices keyframed independently, without the need to adjust a vertex position in every frame. Note also that Colour Selection masks cannot be tracked.
<<, <, >, >>: These buttons will track selected masks forwards or backwards. Clicking << or >> will track backwards or forwards by multiple frames, and clicking < or > will track backwards or forwards by one frame. These controls will be familiar as we used them in them in the Tracking Panel on our last tutorial.
Tracking Mode: These buttons allow the mask tracking mode to be changed. This defines the type of motion that will be tracked for each mask. Combinations of Translate, Rotate and Scale can be specified, along with Affine and Planar Perspective motion.
Use pixels %: This slider specifies the percentage of pixels used to estimate the tracking transformation. Decreasing this value will speed up the tracking process, but decreasing it by too much may mean important image information is lost, reducing tracking accuracy.
Outliers %: This slider can be used to enter the approximate number of outlier pixels (i.e. pixels that are not actually part of the layer) when using the Robust tracking tracking mode described below.
Compensate for illumination: When enabled, small changes in image brightness will be compensated for during tracking. Note that the compensation for brightness is assumed to be the same for all pixels inside the mask.
Use robust tracking: When enabled, it is assumed that some of the pixels contains inside the mask are not actually part of the object being tracked, and should therefore be ignored during tracking. This may be, for example, because part of the image is corrupted or hidden by additional image features. The approximate percentage of these ‘bad’ pixels is controlled using the Outliers % edit box described above.
Use incremental tracking: When enabled, the tracking template (i.e. the image that is being matched in each frame) will be updated at every frame. This means that when tracking over a large number of frames, the tracking template is able to adapt to small changes in the image content. However, it also means that the mask may drift out of position when compared to the starting frame. Note that this is equivalent to using the < or > buttons to repeatedly track the mask over multiple frames.
For this tutorial we are going to leave the parameters at their default positions as nothing is occluding the area we want to track. Let’s now go ahead and track forwards. We can see the mask is moving with the characters face automatically making minor adjustments as it tracks forwards. Once it is complete step through the clip and check the track. We can see it’s done a great job at following the characters face and we could now using the techniques we described early go through and insert some keyframes to keep the mask in the correct location.