Reverse compositing – now with video!

If you’ve used Mistika (or any other software) for compositing images with an alpha channel, you’ve probably had challenges with premultiplied or matted colors. Mistikas Comp3D layers have a parameter labeled Attributes Premultiply* which let’s you work as if the image was never premultiplied as all. This works well for with basic premultiplied/black matted images, but what if it’s matted against another color or even a background image? Let’s have a look at how to get around this and even use white-matted PSD’s directly in Mistika.

* The parameter labeled premultiply should rather be labeled premultiplied, as setting it to yes implies that it’s already been multiplied by the alpha and that Mistika should not do it again when compositing. Correct me if wrong.

Technical details

Digital compositing takes a foreground (f), an alpha channel (a) and a background (b) to create a composite (c). This must be done for each color channel (r, g, b):

c = α f + (1 − α) b

What we want is basically to extract the original foreground from a matted/composited file. It’s basic algebra, and when isolating f, we get something like this:

( c – (1 – a) b ) / a = f

When using this in a new composite, we can save a lot of computing power by not dividing by alpha, but instead enable the premultiplied parameter in the Comp3D layer:

premultiplied f = c – (1 – a) b

Stacking it

The easiest stack is for white matted images like psd files. Since the background is always 1 we don’t need to multiply the inverted alpha at all:

  • Channels: RGB = RGB – inv A

If the background is not 0 (black, premultiplied) or 1 (white), we need a bigger stack:

  • Channels: RGB = RGB1 -RGB2
    • Foreground w/alpha
    • Channels: RGB = RGB * A2
      • Background
      • Foreground w/alpha

This requires both inputs to be the same resolution, so if you have a files in different size than your working resolution, you can’t just use a solid in that color as background. You can however use the following trick to create a solid with the same resolution as your image:

  1. Create a Solid effect and set/eyedrop the matte color
  2. Duplicate your image and put a Channels effect on it, and set Red, Green and Blue Operation to Out=1
  3. Copy the Red, Green and Blue color parameters from the solid into the Scale paramaters of Red, Green and Blue

You now have a solid with the same dimensions as your input!

Take a look at the video on top of the page, and make sure you have a look at these stacks. Enjoy.

4 Responses to “Reverse compositing – now with video!”

  1. Gustavo says:

    i don get it heheheheh, but you are a genius

  2. I know this is a tricky subject, so I really need to get the video tutorial done for this one…

  3. The video is up now. Have a look at the top of the page.

  4. raj says:

    My apologies as this query is not related to video at all.
    But would really appreciate if you could help me with this..

    Faster Mistika even after ingesting 2TB or 5TB rushes ??

    Could somebody give us a quick work around for this issue.
    dont want mistika to open the previously opened project by default.
    Can we do some setting change in {Mconfig} setup or some upgrade patch to open a brand new project.

    THe issue which I have is
    we imported close to 2TB footage more than “3000” .r3d files.. to the browser window.
    and everytime we open mistika…this last opened project with all those files is making it very slower.
    and by the time we open some old project Or a demo Project or create a new project its taking too much time.
    NOTE:- WORKING on a HIGHend unit with Z800 only.

    Happy Coloring!

    GUESS you are also on Mistika User Group on Google groups ??