Premultiplication Problem
by David Frisk
on
Sep 10, 2008 at 4:21:32 am
Sorry for the long post, but PLEASE someone help me understand!
I'm going through Paolini's Shake 4 book, and I've already come across some confusion in the second chapter. It deals with premultiplication.
So apparently if you have a foreground element with an alpha channel, and you have a background element, you can use the "over" node to comp them together. Now if I want to add a type of color correction to the foreground element, such as an "add", and I place it directly after my foreground element, but before my "over" node, it still effects the background. I don't understand why this is. It doesn't happen when I use a "brightness" node, "saturation" node, or a few others...but it will effect the background if I use "add", "invert", and probably a couple more. The solution is apparently to add an "mdiv" node before my color effect, and then check the premultiply checkbox in the "over" node, and it will limit just my effect to the foreground. But I'm the type of person that likes to know what is happening and why something is happening. The book doesn't really clear that up all too well. And I noticed that if I didn't add the "mdiv" node, and just clicked on the premultiply checkbox in the over node, it would still fix the problem (which makes me understand the point of the "mdiv" node even less)
I come from a heavy after effects background, and from my understanding, when talking about alpha channels, you have either straight or premultiplied...and they both actually have the exact same alpha channel...it's the image that differs between the two. Either the image bleeds past the bounds of the alpha channel (and therefore doesn't pick up any background color in the edges) or the image falls off right at the edge of the alpha (and therefore picks up some of the background color in the edges). Either way, the actual alpha channel is identical. In After Effects, you could tell it what kind of alpha you have so that it would automatically remove some of the fringing, but even if you didn't, it in no way affected the effects you applied on it.
I did a test and filled an entire image with red in photoshop, made an alpha channel as a small circle in the middle of it (but just on the alpha channel...I still left the entire image red), and exported out a tiff and brought it into shake. In shake when I piped the image into the "over" node, it left the entire image almost completely red. There was a solid red circle where the alpha channel was, but there was a red semi-transparent area filling the rest of it. So that tells me that it could obviously see the alpha channel, but instead of cutting out the black areas (the way the alpha was made), it only made them semi-transparent. I could either add an "mmult" node to fix it, or check the premultiply checkbox in the "over" node (I don't seem to have to do both like the book suggests).
I'm just thoroughly confused on what is going on. It obviously sees the alpha channel and what I want cut out, so why doesn't it just cut it out? Why does it seem to instead pick some arbitrary amount of transparency to make it instead of seeing that the alpha is full black in these places and therefore I want it transparent? Why do I have to tell it to not effect the background when I'm only piping a color correction into the foreground, and why does it only do that for some color correction effects and not others? When I add an "mdiv" node, what exactly is it doing that allows me to color correct and not effect everything else? Why do I apparently not even have to add that node and instead just check the premultiply box in the "over" node when the book is telling me to do both? I guess I just want to know exactly what is going on behind the scenes here.
Sorry for typing out what is basically a mini novel, but I'm very frustrated that I can't understand this. I usually pick up the technical aspects of programs unusually quick...but I guess I usually find some resource that can spell things out exactly the way things are happening...So far, this book and the manual both don't really give an in-depth explanation as to why these things work the way they work, but rather just skip to what I should do to avoid it. Sure it explains what premultiplication is, but it doesn't explain how shake apparently handles all this information.
Re: Premultiplication Problem by Les Stuck on Sep 10, 2008 at 10:26:37 pm
Premultiplication does not affect the alpha channel. It multiplies the rgb channels
by the alpha channel, so that anything that is black in the alpha channel becomes
black in the rgb channels. (Anything grey in the alpha channel becomes darker
in the rgb, and anything white in the alpha channel is unchanged in rgb.)
You can do the premult either with a MMult or by turning on the premult option
in certain nodes.
Undoing the premult can be either with a MDiv or by turning off the premult option
in certain nodes.
If you try to color-correct a premultiplied image, you will also modify the black
around the image and make it something other than black, which is unfortunate.
Therefore, one should color correct UNpremultiplied images and then premultiply
them later if necessary.
The Over mode expects a premultiplied foreground. Another approach is to use
the Keymix node which has a third input for an alpha channel.
The Paolini book is pretty good, useful for passing the Apple certification test,
but sometimes confusing. I had to Google for a long time before I understoond
premultipication.
As an extra bonus (!) I am including my list of mistakes in the Paolini book
and in tutorial that comes with Shake (you should study both).
Les
Here are some documentation errors,
from Paolini's Apple Pro Training series book:
Adding a node to a noodle (p. 56, #6; p. 264, #7.).
Press the n key until the node knots
turn yellow, then release the mouse button.
Illustration, p. 148. All colors are destination colors, not source.
Review questions, p. 169, #2: Concatenation also prevents clipping.
Review questions, p. 169, #4: "as well as in the ColorReplace tab
in the Color tool tab."
p. 326, #11: First parameter should be xPan, not xPixels.
Second parameter should be yPan, not yPixels.
Keyboard shortcuts, p. 352, Multiplane view: 3 is perspective, 5 top.
Keyboard shortcuts, p. 392: +/= zooms in, -/_ zooms out.
Here are some documentation errors in the Apple Tutorial that comes
with the application.
p. 48: hold n to insert node in noodle.
p. 56, Tips: "Turn on the Select Group button to load only the selected nodes..."
p. 138, #1: "drag right edge of the clip to frame 76."
p. 138, four locations: "VLUT2" should be "g/o/log".
Re: Premultiplication Problem by Burt Hazard on Sep 10, 2008 at 10:37:09 pm
Wow, I did the SHAKE 4 book a long time ago when I first bought Shake and probably attributed the errors to my own incompetence! Interesting.
David, I agree that Shake can be totally confusing when you first get into it and there are a bunch of gotchas that you will run into, but actually the manual does have a pretty good explanation of how Shake handles premultiplication differently than other packages starting (in the PDF version that I'm looking at right now) at page 421.
To give a quick rundown (copied from the manual):
In a Nutshell—the Rules of Premultiplication
If you don’t read the full explanation of the mathematics of premultiplication, here
are the two rules you must always follow when creating a composition in Shake:
• Rule Number 1: Always color correct unpremultiplied images. To unpremultiply an
image, use a Color–MDiv node.
• Rule Number 2: Always filter and transform premultiplied images. To premultiply an
image, use a Color–MMult node.
I may understand...just one missing piece of the puzzle by David Frisk on Sep 11, 2008 at 2:11:42 am
Thanks for the explanation guys. It's much appreciated. I guess I can say I understand what premultiplication is (or at least I think I do), but I still don't get how Shake is going about handling it. Let's take the whole color correction thing out of the equation for right now and just talk about alpha channels in general.
(Just as a side note...I'm sorry if I'm making this more difficult than it really is, but I really want to understand this. I don't want to just know how to work around it. I really want to know what's going on under the hood. So thanks for your patience.)
Let's say I make an image from scratch in photoshop. I make half of it completely blue and the other half completely black. Now I make an alpha channel that is just the shape of a circle, with half of that circle covering the black half and the blue half, and a lot of the rest of the image outside of the white of the alpha. Now I bring it into shake...
When I bring it into shake, the file-in node shows the image as half black and half blue. So I think to myself, okay, I guess it just doesn't put the alpha channel into the equation when viewing it straight from the file-in node. I can switch to the alpha view and see my circle, but in RGB mode it doesn't come into play.
So then I use the over node to put my image from photoshop over some arbitrary background. This is where I don't get what's going on. When I do this I get confused as to what it's doing. Where my alpha channel was white, it cuts out a perfect circle. Half of the circle is black and half of it is blue (since I put it over both the black and blue sections. Where the alpha channel is black, it's half fully transparent and half semi-transparent tinted blue.
So this is what I'm gathering it's doing...It looks at the alpha channel, and wherever it's white, it keeps the RGB colors that were there. Wherever it's black, it doesn't just cut out. It looks at what the RGB colors are where the alpha channel is black. If the RGB color is black where the alpha channel is black, then it becomes transparent. If the RGB value is not completely black in the black alpha area, it only makes it semi-transparent.
So that's what confuses me. I thought the alpha channel determines what is and what isn't transparent. If the alpha channel is white, it should be opaque. If the alpha channel is completely black, it should be completely transparent. Why does it matter what RGB color I have underneath the black alpha channel?
If premultiplying means multiplying the alpha channel by the RGB channel, then shouldn't any areas of black alpha mean transparent no matter what? Black is 0...any RGB color value (of any number) multiplied by a black alpha channel (which is 0) should come out 0 (transparent) in the end. So why do I see a sem-transparent blue where my black alpha channel is?
I HAD AN EPIPHONY! I'm going to go out on a limb and guess that images that are brought in with an alpha channel are not automatically premultiplied by default. Please tell me that's right, as it will finally get me at least half way there to understanding. That would explain why the blue area is not completely transparent...because if it's not premultiplied, then that means the blue is not being multiplied by the black and therefore not giving me the result of 0. It would also explain why I have to check the "premultiply"
box in the "over" node...to tell it that I want to premultiply it since it doesn't do it by default. Is that right? Please tell me that's what's going on!
If that explanation is correct, then that just leaves one last piece of the puzzle to understand. If it isn't premultiplied by default, than what is it by default? What mathematical equations are going on to tell it to look in the black sections of the alpha channel and where its RGB is black, make it transparent, and where it's RGB is white, make it opaque. What is that called? Because to me, that seems like an alpha channel within an alpha channel.
Re: I may understand...just one missing piece of the puzzle by Les Stuck on Sep 11, 2008 at 4:39:21 am
> images that are brought in with an alpha channel are not automatically premultiplied by default.
Correct, the image you made in Photoshop is NOT premultiplied,
and Shake WON'T do the premultiplication unless you explicitly tell it to.
>If it isn't premultiplied by default, than what is it by default?
Unpremultiplied. In other words, the RGB channels are unchanged.
You are being confused by the action of the Over node. The over node
uses the alpha channel to determine what is visible. Instead of making the
alpha-black area black (premultiplication), it makes them TRANSPARENT.....
BUT if the background black, they will appear black.
Re: I may understand...just one missing piece of the puzzle by David Frisk on Sep 11, 2008 at 9:15:18 pm
Haha, no worries.
Thank you so much for taking the time to explain it. You are right, the action of the over node was getting me tripped up. I didn't realize it kind of did it's own thing, and I didn't realize that you had to explicitly tell Shake that you wanted things premultiplied. This makes things much, much clearer. Thanks again for your patience in helping me understand it.
Re: Premultiplication Problem by Eric Meek on Oct 21, 2008 at 1:01:34 pm
This is shake man, not some app with pre cooked ways to do things. Shake doesnt MAKE the decision for you like AE does. Shake lays EVERYTHING out on the table. You have to add an mdiv etc because your using shake. It assumes nothing. There are several ways to use an Alpha and shake doesnt assume anything like AE. Shake users like to tell shake what to do in every little aspect, we like to control even the little things like that and it a huge script it is necessary. If AE does it for you, than what if an artist gets a hold of your work? Do they have any clue whats going on without having to dig into layers? With shake, every color correction, every mdiv and mmult is laid out right in front of you in the tee. If any other artist gets the work every single step is right in front of him. He doesnt have to dig into layers or nodes to see whats happening. Bottom line, in Shake, you do everything. Every single minute detail can be controlled, unlike AE. And this controllable app is why shake is loved so much. This post doesnt answer the direct question you had but i seen the other post do a good job at that. I wanted to explain why it does it that way. Because it assumes nothing of you adn you control every single aspect of your project. And for professional compositors this is the only way to work. You can see now why ,to me, AE was never a professional app but a prosumer app. Even though it can and has been used professionally its not shake.
Re: Premultiplication Problem by David Frisk on Oct 21, 2008 at 1:14:25 pm
"There are several ways to use an Alpha and shake doesnt assume anything like AE."
After Effects doesn't do it for you. You can tell AE to ignore the alpha channel of a layer, tell it that it's premultiplied with a specific color, or tell it that it's a straight alpha channel. No lack of control there.
"And for professional compositors this is the only way to work. You can see now why ,to me, AE was never a professional app but a prosumer app."
No, it's not the only way to work, because professionals use AE all the time. I've seen your youtube videos and I know how wrong you are with a lot of your preconceived notions. AE is used A LOT. I've worked on a TV show and a few movies out in Hollywood, and they all used after effects...one of them using it exclusively.