From ripley at stats.ox.ac.uk  Mon Apr  3 12:28:58 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 3 Apr 2006 11:28:58 +0100 (BST)
Subject: [Rd] pixmaps and R
In-Reply-To: <4430F2F4.6000709@biomserv.univ-lyon1.fr>
References: <4423FE7D.8020907@biomserv.univ-lyon1.fr>
	<442738C0.6020800@jhsph.edu>
	<17447.39695.821834.393844@celebrian.ci.tuwien.ac.at>
	<4430F2F4.6000709@biomserv.univ-lyon1.fr>
Message-ID: <Pine.LNX.4.64.0604031121370.18803@gannet.stats.ox.ac.uk>

On Mon, 3 Apr 2006, Thibaut Jombart wrote:

> Hello list,
>
> here is a question relative to pixmap pictures in R. Manipulating such
> objects is quite demanding for the RAM, as large matrices are created.
>
> For instance, try to execute the example of rimage library :
>
> ### R code ###
> library(rimage)
> x <- read.jpeg(system.file("data", "cat.jpg", package="rimage"))
> plot(x)
> object.size(x)
> save.image()
> ### end of R code ###
>
> Moreover, the '.RData' will be approximately the size of 'x' (around 4
> MB), despite the jpeg size is only 16 KB.

You can of course use compression when saving here, via 
save(compress=TRUE). But it will not help much, as you are storing a very 
simple image in a floating-point format with 24 bytes per pixel.  I 
suggest you use a more suitable format: JPEG files are only 8bits per 
channel, so could be stored in a raw not numeric vector.


> Of course it is possible store only the expression reading the pictures
> instead.
> For instance:
>
> ### R code ###
> y=expression(read.jpeg(system.file("data", "cat.jpg", package="rimage")))
> object.size(y)
> object.size(eval(y))
> plot(eval(y))
> ### end of R code ###
>
> But... does anybody know if compressed pictures could be stored in R?
> And if yes, how ?
>
> Thanks,
>
> Thibaut.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] pixmaps and R
Prof Brian Ripley