[R] displaying intensity through opacity on an image (ONE SOLUTION)

Ranjan Maitra maitra at iastate.edu
Sat May 19 07:05:11 CEST 2007


Dear list, 

I did not get any response yet, but after looking around R and other things, I came up with something that works.

Basically, I use the rgb() function in R [though I could also use the hsv() function] to help me with the colormap.

Anyway, doing a help on rgb gives:


     This function creates "colors" corresponding to the given
     intensities (between 0 and 'max') of the red, green and blue
     primaries.

     An alpha transparency value can also be specified (0 means fully
     transparent and 'max' means opaque). If 'alpha' is not specified,
     an opaque colour is generated.

     The names argument may be used to provide names for the colors.

     The values returned by these functions can be used with a 'col='
     specification in graphics functions or in 'par'.

and later on.....

     Semi-transparent colors ('0 < alpha < 1') are supported only on a
     few devices: at the time of writing only on the 'pdf' and (on
     MacOS X) 'quartz' devices.

The hsv() function has a similar point on semi-transparent colors.


Ok, looks promising: I don't use a Mac, and my potential journal does not accept .pdf, only .tiff or .eps, but we are not totally lost here.

So, I tried the following silly example in R:


> pdf()

> image( matrix(rep(1:5,5), nr = 5), col = gray(0:16/16)) 

> image( matrix(1:25, nr = 5), col = rgb(rep(1, 15), g=0, b=0, alpha =
  rep(1:15)/15), add = T) # red with different opacities 

> q()

(we are out of R).

And then look at the pdf file created: by default it is Rplots.pdf.

OK, now we can use gimp, simply to convert this to .eps. Alternatively on linux, the command pdftops and then psto epsi on it would also work.

Yippee! Isn't R wonderful??

Hope this helps: though others may have known about this before, I certainly did not know how to do this in R.

Best wishes,
Ranjan







On Thu, 17 May 2007 19:16:18 -0500 Ranjan Maitra <maitra at iastate.edu> wrote:

> Dear colleagues,
> 
> I have an image which I can display in the greyscale using image. On this image, for some pixels, which I know, I want to display their activity based on a third measure. One way to do that would be to color these differently, and use an opacity measure to display the third measure. An example of what I am trying to do is at:
> 
> http://www.public.iastate.edu/~maitra/papers/mrm02.pdf
> 
> page 26, for instance. There are two different kinds of voxels, given by greens and red. At the low end, there is transparency on the red scale and at the upper end there is opacity in the red and the green. 
> 
> A simpler example involving only one kind of voxels is on page 24 of the same paper. Either way, that figure was done using Matlab, but I was wondering how do i do this using R.
> 
> Any suggestions, please?
> 
> Many thanks and best wishes,
> Ranjan 
>



More information about the R-help mailing list