On Tue, 28 Aug 2001, Agustin Lobo wrote:
>
> Does anyone know if it is possible
> to display jpeg (and/or other image
> formats) images using R? I would need
> to overlay results of contour() on
> color maps.
>
Use a tool of your choice to convert the jpeg to pnm (say in Gimp). Then
use the e1071 package:
> library(e1071)
> pix <- read.pnm("your.pnm")
> plot(pix, asp=T) # asp to keep aspect ratio if you need it
> d <- dim(pix)
> col <- pix[1,,]
> z <- matrix(col, nrow = d[2])
> contour(x = 1:d[3], y = 1:d[2], z = t(z[d[2]:1, ]), col =
"white",
add=T, nlevels=3)
When adding contours (here for three levels of the first colour in the
image), you need to watch out for plot.pnm using upper, not lower, left as
1,1; that is the image follows usual image practice, so your data will
have to suit that to be in the "right" place. Here the contour plot is
of
the image data, so needs "fixing" to come right. The image is read in
from
the upper left, and the plot in plot.pnm is in the pixel coordinate
system, so overlaying may be the major problem here - getting the image
and the contoured data registered correctly. The example above is trivial,
because it is contouring image data.
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
and: Department of Geography and Regional Development, University of
Gdansk, al. Mar. J. Pilsudskiego 46, PL-81 378 Gdynia, Poland.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._