[R] color blending and transparency
Thomas Lumley
tlumley at u.washington.edu
Wed Feb 3 17:04:02 CET 2010
On Wed, 3 Feb 2010, baptiste auguie wrote:
> That makes perfect sense, thank you, except that I'm not sure where
> the white comes from when I set the background to transparent?
>
> png("testingOrder.png", bg = "transparent")
> plot.new()
> par(bg="transparent")
> rect(0.3, 0.5, 1, 1, col=rgb(1, 0, 0, alpha=0.5))
> rect(0, 0.5, 0.7, 1, col=rgb(0, 0, 1, alpha=0.5))
>
> rect(0, 0, 0.7, 0.5, col=rgb(0, 0, 1, alpha=0.5))
> rect(0.3, 0, 1, 0.5, col=rgb(1, 0, 0, alpha=0.5))
>
> dev.off()
>
> Still produces two different overlap colours, although I *think* only
> two colours are involved. What I have I missed here?
My mental model for this, which I haven't bothered to check against the actual algorithms, is that colors are composed of reflective/absorbing pigment particles and that alpha says how densely they are packed. Alpha=0 means all the light gets through to bounce of what ever is below, eventually to the white paper, and alpha=1 means that all the light is reflected from the top layer of paint.
With 50% blue over 50% red, you reflect 50% of the blue light and absorb 50% of the red and green light in the top layer of paint. Of the remaining light, 50% of the red is reflected and 50% of the green and blue absorbed by the particles in the bottom layer of paint. Anything that makes it through will reflect off the white paper.
There is the additional complication that a transparent background still behaves as if it had white paper behind it (it's drawn on an acetate sheet which you lay on paper to see it more clearly).
-thomas
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list