[R] overlay two pixmap

Roger Bivand Roger.Bivand at nhh.no
Fri Sep 26 12:44:35 CEST 2003


Christoph Lehmann wrote:

> I need to overlay two pixmaps (library (pixmap)). One, a pixmapGrey, is
> the basis, and on this I need to overlay a pixmapIndexed, BUT: the
> pixmapIndexed has set only some of its "pixels" to an indexed color,
> many of its pixels should not cover the basis pixmapGrey pixel, means,
> for this "in pixmapIndexed not defined pixels" it should be transparent.

> What would you recommend me to do? Should I go for another solution than
> pixmap?

Determine which of the indexed colours in the pixmapIndexed object are to 
be transparent, and change them to NA - you access them in say:

library(pixmap)
x <- read.pnm(system.file("pictures/logo.ppm", package = "pixmap")[1])
x
plot(x)
xx <- as(x, "pixmapIndexed")
xx
plot(xx)
example(pixmap)
z <- pixmapRGB(c(z1, z2, z3), 100, 100, bbox = c(0, 0, 100, 100))
plot(z)
xx at col[1:20]
xx at col[1] <- NA
plot(xx, add=T)

Here xx at col[1] was "white" aka "#FFFFFF", you could use col2rgb() to help 
set thresholds. Admittedly, this is messy if you don't know your 
threshold.

Roger

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list