[R] color blending and transparency

2010-02-03 Thread bluecuttlefish
I am using ggplot and posted this question at that helplist. It was
suggested that I try a more general R-help list for a possible solution to
this problem.

Within ggplot, I am using geom_area with red and blue and expect where they
overlap should be purple. But instead, it's dark red.

Playing with alpha and with different colors doesn't seem to solve the
problem.

Here's a very simple reproducible example

R --arch x86_64

library(ggplot2)

x-c(24,55,69,73)
y-c(44,56,12,90)
z-c(1,2,3,4)
a-data.frame(pos=z, y=y, x=x)

ex- ggplot(data=a, aes(pos)) +
geom_area(aes(y = y),fill=navyblue, alpha = 0.7, position=identity) +
geom_area(aes(y = x), fill= darkred, alpha = 0.7,position=identity ) +
opts(panel.background = theme_rect(fill = white))

ex

Likewise, with blue and yellow, I would expect overlap to be green.
Are there any solutions to this that would allow color overlaps to lead to
the expected color?
Thank you.

 sessionInfo()
R version 2.10.0 (2009-10-26)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid  stats graphics  grDevices utils datasets  methods
[8] base

other attached packages:
[1] ggplot2_0.8.3 reshape_0.8.3 plyr_0.1.9proto_0.3-8

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread Jim Lemon

On 02/03/2010 08:43 PM, bluecuttlefish wrote:

I am using ggplot and posted this question at that helplist. It was
suggested that I try a more general R-help list for a possible solution to
this problem.

Within ggplot, I am using geom_area with red and blue and expect where they
overlap should be purple. But instead, it's dark red.

Playing with alpha and with different colors doesn't seem to solve the
problem.

Here's a very simple reproducible example

R --arch x86_64

library(ggplot2)

x-c(24,55,69,73)
y-c(44,56,12,90)
z-c(1,2,3,4)
a-data.frame(pos=z, y=y, x=x)

ex- ggplot(data=a, aes(pos)) +
geom_area(aes(y = y),fill=navyblue, alpha = 0.7, position=identity) +
geom_area(aes(y = x), fill= darkred, alpha = 0.7,position=identity ) +
opts(panel.background = theme_rect(fill = white))

ex

Likewise, with blue and yellow, I would expect overlap to be green.
Are there any solutions to this that would allow color overlaps to lead to
the expected color?


Hi bluecuttlefish,
Think ink - should be easy. Only certain devices support transparency. 
Have you tried this on the pdf device?


Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread baptiste auguie
Hi,

Adding two semi-transparent colours results in non-intuitive colour
mixing (a mystery for me anyway). Is it additive (light), substractive
(paint), or something else? Consider the following example, depending
on the order of the two layers the overlap region is either purple
or dark red. I have no idea why.

png(testingOrder.png)
plot.new()

# Red below
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))

# Blue below
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()


Best,

baptiste

On 3 February 2010 11:15, Jim Lemon j...@bitwrit.com.au wrote:
 On 02/03/2010 08:43 PM, bluecuttlefish wrote:

 I am using ggplot and posted this question at that helplist. It was
 suggested that I try a more general R-help list for a possible solution to
 this problem.

 Within ggplot, I am using geom_area with red and blue and expect where
 they
 overlap should be purple. But instead, it's dark red.

 Playing with alpha and with different colors doesn't seem to solve the
 problem.

 Here's a very simple reproducible example

 R --arch x86_64

 library(ggplot2)

 x-c(24,55,69,73)
 y-c(44,56,12,90)
 z-c(1,2,3,4)
 a-data.frame(pos=z, y=y, x=x)

 ex- ggplot(data=a, aes(pos)) +
 geom_area(aes(y = y),fill=navyblue, alpha = 0.7, position=identity) +
 geom_area(aes(y = x), fill= darkred, alpha = 0.7,position=identity ) +
 opts(panel.background = theme_rect(fill = white))

 ex

 Likewise, with blue and yellow, I would expect overlap to be green.
 Are there any solutions to this that would allow color overlaps to lead to
 the expected color?

 Hi bluecuttlefish,
 Think ink - should be easy. Only certain devices support transparency. Have
 you tried this on the pdf device?

 Jim

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread Ken Knoblauch
baptiste auguie baptiste.auguie at googlemail.com writes:
 Adding two semi-transparent colours results in non-intuitive colour
 mixing (a mystery for me anyway). Is it additive (light), substractive
 (paint), or something else? Consider the following example, depending
 on the order of the two layers the overlap region is either purple
 or dark red. I have no idea why.
 
 png(testingOrder.png)
 plot.new()
 
 # Red below
 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))
 
 # Blue below
 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()
I would expect overlaid transparencies to act like filters and
multiply, producing so-called subtractive color mixing,
so blue and yellow gives green.  Interestingly, however,
overlaying filters is not necessarily a commutative 
operation, since a transparent filter can yield an
additive component (through scatter, for example)
though I suspect that the non-commutativity comes
about in R because these rules apply to physical lights,
filters and surfaces and in R, it is some uncalibrated combination
of frame buffer values that is being used.  

 Best,
 
 baptiste
 

Ken

-- 
Ken Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread Duncan Murdoch

On 03/02/2010 8:50 AM, Ken Knoblauch wrote:

baptiste auguie baptiste.auguie at googlemail.com writes:

Adding two semi-transparent colours results in non-intuitive colour
mixing (a mystery for me anyway). Is it additive (light), substractive
(paint), or something else? Consider the following example, depending
on the order of the two layers the overlap region is either purple
or dark red. I have no idea why.

png(testingOrder.png)
plot.new()

# Red below
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))

# Blue below
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))


I think it's a fairly simple calculation.  In the first example: We are 
writing red (1,0,0) at alpha=0.5 onto white (1,1,1), so we get a mixture 
of half existing and half new, i.e. (1,0.5,0.5).  Then we write blue 
(0,0,1) at alpha 0.5 onto that, giving (0.5, 0.25, 0.75).


In the second pair, the first write yields (0.5,0.5,1), and the second 
yields (0.75, 0.25, 0.5).


So this is like mixing paints:  you don't get the same colour if you mix 
equal parts red and white, then take equal parts of that mixture with 
blue, as you get if you put the blue in first.  You've got less red in 
the first mixture than in the second.


You would get the same color in both mixtures if you didn't mix the 
white in:


# Red below
rect(0.3, 0.5, 1, 1, col=rgb(1, 0, 0, alpha=1))
rect(0, 0.5, 0.7, 1, col=rgb(0, 0, 1, alpha=0.5))

# Blue below
rect(0, 0, 0.7, 0.5, col=rgb(0, 0, 1, alpha=1))
rect(0.3, 0, 1, 0.5, col=rgb(1, 0, 0, alpha=0.5))


Duncan Murdoch



dev.off()

I would expect overlaid transparencies to act like filters and
multiply, producing so-called subtractive color mixing,
so blue and yellow gives green.  Interestingly, however,
overlaying filters is not necessarily a commutative 
operation, since a transparent filter can yield an

additive component (through scatter, for example)
though I suspect that the non-commutativity comes
about in R because these rules apply to physical lights,
filters and surfaces and in R, it is some uncalibrated combination
of frame buffer values that is being used.  


Best,

baptiste



Ken



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread baptiste auguie
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?

Thanks,

baptiste


On 3 February 2010 15:17, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 03/02/2010 8:50 AM, Ken Knoblauch wrote:

 baptiste auguie baptiste.auguie at googlemail.com writes:

 Adding two semi-transparent colours results in non-intuitive colour
 mixing (a mystery for me anyway). Is it additive (light), substractive
 (paint), or something else? Consider the following example, depending
 on the order of the two layers the overlap region is either purple
 or dark red. I have no idea why.

 png(testingOrder.png)
 plot.new()

 # Red below
 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))

 # Blue below
 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))

 I think it's a fairly simple calculation.  In the first example: We are
 writing red (1,0,0) at alpha=0.5 onto white (1,1,1), so we get a mixture of
 half existing and half new, i.e. (1,0.5,0.5).  Then we write blue (0,0,1) at
 alpha 0.5 onto that, giving (0.5, 0.25, 0.75).

 In the second pair, the first write yields (0.5,0.5,1), and the second
 yields (0.75, 0.25, 0.5).

 So this is like mixing paints:  you don't get the same colour if you mix
 equal parts red and white, then take equal parts of that mixture with blue,
 as you get if you put the blue in first.  You've got less red in the first
 mixture than in the second.

 You would get the same color in both mixtures if you didn't mix the white
 in:

 # Red below
 rect(0.3, 0.5, 1, 1, col=rgb(1, 0, 0, alpha=1))
 rect(0, 0.5, 0.7, 1, col=rgb(0, 0, 1, alpha=0.5))

 # Blue below
 rect(0, 0, 0.7, 0.5, col=rgb(0, 0, 1, alpha=1))
 rect(0.3, 0, 1, 0.5, col=rgb(1, 0, 0, alpha=0.5))


 Duncan Murdoch


 dev.off()

 I would expect overlaid transparencies to act like filters and
 multiply, producing so-called subtractive color mixing,
 so blue and yellow gives green.  Interestingly, however,
 overlaying filters is not necessarily a commutative operation, since a
 transparent filter can yield an
 additive component (through scatter, for example)
 though I suspect that the non-commutativity comes
 about in R because these rules apply to physical lights,
 filters and surfaces and in R, it is some uncalibrated combination
 of frame buffer values that is being used.

 Best,

 baptiste


 Ken


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread Duncan Murdoch

On 03/02/2010 9:38 AM, 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?
  


You'd have to check the png device documentation or source code to find 
out what it does when you mix half red with half transparent.  When I 
view a .png file
in the default viewer in Windows 7, setting the background to 
transparent displays it as white, I don't see the things behind the 
window showing through.  I don't know if it's the viewer or the file 
determining that.


Duncan Murdoch

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?

Thanks,

baptiste


On 3 February 2010 15:17, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 03/02/2010 8:50 AM, Ken Knoblauch wrote:

 baptiste auguie baptiste.auguie at googlemail.com writes:

 Adding two semi-transparent colours results in non-intuitive colour
 mixing (a mystery for me anyway). Is it additive (light), substractive
 (paint), or something else? Consider the following example, depending
 on the order of the two layers the overlap region is either purple
 or dark red. I have no idea why.

 png(testingOrder.png)
 plot.new()

 # Red below
 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))

 # Blue below
 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))

 I think it's a fairly simple calculation.  In the first example: We are
 writing red (1,0,0) at alpha=0.5 onto white (1,1,1), so we get a mixture of
 half existing and half new, i.e. (1,0.5,0.5).  Then we write blue (0,0,1) at
 alpha 0.5 onto that, giving (0.5, 0.25, 0.75).

 In the second pair, the first write yields (0.5,0.5,1), and the second
 yields (0.75, 0.25, 0.5).

 So this is like mixing paints:  you don't get the same colour if you mix
 equal parts red and white, then take equal parts of that mixture with blue,
 as you get if you put the blue in first.  You've got less red in the first
 mixture than in the second.

 You would get the same color in both mixtures if you didn't mix the white
 in:

 # Red below
 rect(0.3, 0.5, 1, 1, col=rgb(1, 0, 0, alpha=1))
 rect(0, 0.5, 0.7, 1, col=rgb(0, 0, 1, alpha=0.5))

 # Blue below
 rect(0, 0, 0.7, 0.5, col=rgb(0, 0, 1, alpha=1))
 rect(0.3, 0, 1, 0.5, col=rgb(1, 0, 0, alpha=0.5))


 Duncan Murdoch


 dev.off()

 I would expect overlaid transparencies to act like filters and
 multiply, producing so-called subtractive color mixing,
 so blue and yellow gives green.  Interestingly, however,
 overlaying filters is not necessarily a commutative operation, since a
 transparent filter can yield an
 additive component (through scatter, for example)
 though I suspect that the non-commutativity comes
 about in R because these rules apply to physical lights,
 filters and surfaces and in R, it is some uncalibrated combination
 of frame buffer values that is being used.

 Best,

 baptiste


 Ken


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread Thomas Lumley

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
tlum...@u.washington.eduUniversity of Washington, Seattle

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread baptiste auguie
On MacOSX I can tell Preview or Photoshop not to use a white
background yet the mixing still shows a difference (with either pdf or
png for that matter). So I guess it's something to do with mixing
colours with the transparent channel as you say. I'll try to find the
reason in the source code later (I haven't found any documentation on
this so far).

Thanks,

baptiste

On 3 February 2010 16:38, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 03/02/2010 9:38 AM, 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?


 You'd have to check the png device documentation or source code to find out
 what it does when you mix half red with half transparent.  When I view a
 .png file
 in the default viewer in Windows 7, setting the background to transparent
 displays it as white, I don't see the things behind the window showing
 through.  I don't know if it's the viewer or the file determining that.

 Duncan Murdoch

 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?

 Thanks,

 baptiste


 On 3 February 2010 15:17, Duncan Murdoch murd...@stats.uwo.ca wrote:
  On 03/02/2010 8:50 AM, Ken Knoblauch wrote:
 
  baptiste auguie baptiste.auguie at googlemail.com writes:
 
  Adding two semi-transparent colours results in non-intuitive colour
  mixing (a mystery for me anyway). Is it additive (light), substractive
  (paint), or something else? Consider the following example, depending
  on the order of the two layers the overlap region is either purple
  or dark red. I have no idea why.
 
  png(testingOrder.png)
  plot.new()
 
  # Red below
  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))
 
  # Blue below
  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))
 
  I think it's a fairly simple calculation.  In the first example: We are
  writing red (1,0,0) at alpha=0.5 onto white (1,1,1), so we get a mixture
  of
  half existing and half new, i.e. (1,0.5,0.5).  Then we write blue
  (0,0,1) at
  alpha 0.5 onto that, giving (0.5, 0.25, 0.75).
 
  In the second pair, the first write yields (0.5,0.5,1), and the second
  yields (0.75, 0.25, 0.5).
 
  So this is like mixing paints:  you don't get the same colour if you mix
  equal parts red and white, then take equal parts of that mixture with
  blue,
  as you get if you put the blue in first.  You've got less red in the
  first
  mixture than in the second.
 
  You would get the same color in both mixtures if you didn't mix the
  white
  in:
 
  # Red below
  rect(0.3, 0.5, 1, 1, col=rgb(1, 0, 0, alpha=1))
  rect(0, 0.5, 0.7, 1, col=rgb(0, 0, 1, alpha=0.5))
 
  # Blue below
  rect(0, 0, 0.7, 0.5, col=rgb(0, 0, 1, alpha=1))
  rect(0.3, 0, 1, 0.5, col=rgb(1, 0, 0, alpha=0.5))
 
 
  Duncan Murdoch
 
 
  dev.off()
 
  I would expect overlaid transparencies to act like filters and
  multiply, producing so-called subtractive color mixing,
  so blue and yellow gives green.  Interestingly, however,
  overlaying filters is not necessarily a commutative operation, since a
  transparent filter can yield an
  additive component (through scatter, for example)
  though I suspect that the non-commutativity comes
  about in R because these rules apply to physical lights,
  filters and surfaces and in R, it is some uncalibrated combination
  of frame buffer values that is being used.
 
  Best,
 
  baptiste
 
 
  Ken
 
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread baptiste auguie
Thanks for this complementary information. My head itches slightly
when reading about these virtual layers with unidirectional absorption
and reflection properties but I guess that's imputable to my personal
background as a physicist.

I still have a few questions,

- is this behavior documented? (I'm happy to look at the source, but
I'm not even sure if it's in grDevices, device specific, or somewhere
else altogether)

- have there been any attempts at implementing other options for
colour blending? It would be nice to be able to switch between
additive and substrative colour mixing rules on occasion, but as far
as I understand the scheme we discussed is hard coded deep into R's
internals (correct?). An option not to use the background at all in
the mixing / reflection process would be great already.

Thanks again,

baptiste


On 3 February 2010 17:04, Thomas Lumley tlum...@u.washington.edu wrote:

 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
 tlum...@u.washington.edu        University of Washington, Seattle



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color blending and transparency

2010-02-03 Thread Thomas Lumley

On Wed, 3 Feb 2010, baptiste auguie wrote:


Thanks for this complementary information. My head itches slightly
when reading about these virtual layers with unidirectional absorption
and reflection properties but I guess that's imputable to my personal
background as a physicist.


It's not unidirectional, it's just infinitesimal thickness -- if the light 
didn't hit a pigment particle in the top layer on the way in, it won't on the 
way out either.  Not realistic, but very physicist ;)


I still have a few questions,

- is this behavior documented? (I'm happy to look at the source, but
I'm not even sure if it's in grDevices, device specific, or somewhere
else altogether)


Several of the devices delegate the computations to the operating system or viewer, so 
that's the easiest way to find the algorithm.  It's the Porter-Duff compositing 
algorithm, the over operator.


- have there been any attempts at implementing other options for
colour blending? It would be nice to be able to switch between
additive and substrative colour mixing rules on occasion, but as far
as I understand the scheme we discussed is hard coded deep into R's
internals (correct?). An option not to use the background at all in
the mixing / reflection process would be great already.


There are some limitations from the ink-on-paper graphics model in R, since the 
resulting color from n layers must be a function only of the resulting color 
from n-1 layers and the top color (and not, for example, a function of n).

Also, for PDF and SVG we are basically limited to models that PDF implements 
automatically, since it isn't feasible to work out which objects overlap and 
adjust their colors that way.


 -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.