Side Quest #8 (Compositor) - move the mask
Hi, this started as a question, but I eventually landed on a couple of workarounds - so I figured it could make a good challenge, hopefully someone has a more straightforward way. My attempts and generally wall of text below the task files, may be it could be of use to someone (edge case as it is).
Task:
"Reveal" the entire house on frame 2, without modifying the mask "House" or changing the tracking (either use the Stabilize 2D or the Translate route). Anything else goes - the less manual labour, the better (e.g., imagine a 100 frames):
Blender file and track images (images need to be in the same folder as the .blend file):
challenge-move-mask.blend-------
As some background, I ran into a headache while trying to stabilize a mask that extends outside the image bounds - specifically the ground in a stabilized shot (there was no single frame that contains all of the ground). You could move the mask and keyframe it, but I was looking for an automated way. I tried a couple of approaches, each with its own problems:
1. Base behavior - it seems the Mask node output considers only the part of the mask within the image boundary (ignoring the extending part), so it is treated like a normal image - thus both Transform operations and Stabilize 2D move this resultant pre-cut mask image, instead of the actual mask, leading to empty strips (where the mask was moved from).
2. I tried to trick this by rendering the mask as an image - set the Render size to double resolution, scaled the mask to half (and positioned it so it is entirely within the image bounds), rendered the result of the Mask node, returned the Render size to normal. Then used this rendered image instead of the original Mask node and aligned it accordingly. So far, so good, except that the Stabilize 2D causes the image (which is twice the Render size) to move double the distance... I guess the node is "smart" enough to take the image size into consideration.
3. At this point I subtracted the Track Position of one of the markers used for stabilization - more-or-less works this time, but it is not exact (as, from the doc, the translation is calculated according to the weighted average of the tracks) and it doesn't really account for rotation (I guess rotation can be calculated, but it seems quite convoluted - and in the end it amounts to reinventing the wheel).
4. Then I tried parenting the mask points to a plane track, but got a rather incorrect shifting across frames.
In the end,
Workaround 1:
Following attempt 2, I dug a bit into the source code and noticed something interesting - Stabilize 2D calls a function which accepts width and height as parameters; the same function is called also from the node Movie Clip. Stabilize 2D passes the Image input's width and height, whereas Movie Clip passes the actually stabilized clip's width and height. Even better, Movie Clip provides the actual X, Y and angle of the stabilization data. A limitation is that the track images cannot be packed in the Blender file, and the Movie Clip node requires them in order to work properly - so the images need to be sent in addition to the file if necessary. And thus, by using the rendered mask image and the Movie Clip node I got the desired result:
Workaround 2:
I duplicated the mask, shifted it in Mask mode on X and on Y by a certain amount. Then in the compositor translated it accordingly to fit with the original, stabilized it and then used Alpha Over to combine it with the original mask in order to fill in the blank edge. In case the image is shifting a lot, add additional masks as needed to fill in the blank edges:
-------
Side question - does it make sense to have some naming convention for such mini-challenges, and is it preferable to have them created only by the CGBoost staff?