[R] Images: array of RBG codes

Henrik Bengtsson hb at maths.lth.se
Fri Jan 3 05:11:02 CET 2003


The core distribution of R does not provide means for reading image
files. However, the 'pixmap' package on CRAN can read Portable PixMap
images, which commonly have extensions PBM (monochrome images), PGM
(grayscale images) and PPM (color/RGB images). You can install the
pixmap package by

  install.packages("pixmap")

If you have images of other formats, e.g. JPEG, BMP, PNG, GIF etc, I
recommend that you use ImageMagick's command line command 'convert' to
convert your images into PPM. ImageMagick exists for many platforms and
can be downloaded from http://www.imagemagick.org/. Say you install a
Windows version of ImageMagick under C:/Program Files/ImageMagick/" then
you can call it from within R by doing:

 system("\"C:/Program Files/ImageMagick/convert.exe\" foo.jpg foo.png")

Note that you need to put any command containing spaces within quotation
marks, thereby the \". You can of course write your own wrapper
function, e.g. readJPG(), which will convert the jpg file to ppm and the
use pixmap to read it in.

Finally, the pixmap package provides methods for getting the red, the
green and the blue channels as matrices.

In other words, it is not to hard to get what you want!

Cheers

Henrik Bengtsson


> -----Original Message-----
> From: r-help-admin at stat.math.ethz.ch
> [mailto:r-help-admin at stat.math.ethz.ch] On Behalf Of Francisco Junior
> Sent: den 3 januari 2003 09:21
> To: r-help at stat.math.ethz.ch
> Subject: [R] Images: array of RBG codes
> 
> 
> People,
> 
> I need to read a figure (JPEG, BMP or PNG) and to transform
> it into integer´s array with RBG code. Are there some library 
> with method for this purpose?
> 
> Thanks,
> Francisco.
> 
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Francisco Júnior,
> Computer Science-UFPE-Brazil
> "One life is valid more than world whole"
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/> r-help
> 
>




More information about the R-help mailing list