dilevin / computer-graphics-raster-images

Computer Graphics Assignment about Raster Images
1 stars 7 forks source link

Compositing: Porter Duff Over operator #41

Closed NPTP closed 4 years ago

NPTP commented 4 years ago

It's not entirely clear what we should be using for the compositing (A over B) part of the assignment. Should we be using this (taken from wikipedia) ? image

If not, there is also this operation shown in lecture and the textbook: image but it looks like this one can only be used if you have the assumption that the background is opaque, and the header file for demosaic.h states that A and B are semi-transparent rgba images so that appears to rule this formula out.

There is also this linear combination given in lecture, but the example shown is Dest Atop, not Over, and it's not clear what parameters are required for Over: image

I have also looked at the provided link (http://ssp.impulsetrain.com/porterduff.html) but it is very unclear how to formulate the "Over" operation from this (the provided table is not exactly instructive).

I am using the formula from wikipedia (which simplifies to the second one shown when background alpha = 1) for the R, G and B values, which seems to work great, just want to be sure this is what is meant in the assignment spec. However there is one probably more important question - I am not sure of how the alpha channel of C should be calculated from A and B and don't see any clear instruction for that using straight alpha (rather than premultiplied). How do we go about that?

Thank you very much!

songfeil commented 4 years ago

You can use the one from wikipedia. Actually the wiki formula is "normalized" version of the third formula, deep down they're the same.

NPTP commented 4 years ago

Thank you. So we use this same formula for the alpha channel as well, treating the alpha values themselves like blending a colour?

songfeil commented 4 years ago

Emm I think in the wiki page they have another equation for alpha value just under the color equation, right? :P

NPTP commented 4 years ago

Oh yeah I did see that of course! But I wasn't sure about it because the phrasing just before it implies the equation requires the assumption that all color values are premultiplied by their alpha values. And I'm not sure I understand it all well enough to have extrapolated that that equation might work in other conditions. I have employed it now anyway though (with a multiplication by 255 to re-scale it)! Thanks for your help.