From huber at ebi.ac.uk  Mon Apr  3 13:20:41 2006
From: huber at ebi.ac.uk (Wolfgang Huber)
Date: Mon, 03 Apr 2006 12:20:41 +0100
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: <44310509.8070109@ebi.ac.uk>

Dear Thibaut,

I am not sure what you want to do and what for you want to have a 
compressed version of an image in R. You can try the EBImage package, 
which is in the devel branch of bioconductor
http://www.bioconductor.org/packages/bioc/1.8/html/EBImage.html
It uses ImageMagick for image I/O and processing (so you need that, 
including header files and Magick++). It is still early in this 
package's life-cycle, so consider it an "alpha" version.

library(EBImage)
y = read.image(system.file("data", "cat.jpg", package="rimage"),
        rgb=TRUE)

object.size(y)
[1] 702888
 > dim(y)
[1] 418 420

and this is 4 Bytes (a 32 bit int of which only the lower 24 bits are 
used) per Pixel, rather than 24 Bytes (3 doubles) in the case below.

object.size(x)  ## your example from rimage
[1] 4214240

And there are some 2D filtering and image processing functions.

Cheers
   Wolfgang

-------------------------------------
Wolfgang Huber
European Bioinformatics Institute
European Molecular Biology Laboratory
Cambridge CB10 1SD
England
Phone: +44 1223 494642
Fax:   +44 1223 494486
Http:  www.ebi.ac.uk/huber
-------------------------------------

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.
> 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.



[Rd] pixmaps and R
Wolfgang Huber