[R] Importing TIFF files into a R matrix

Henrik Bengtsson hb at maths.lth.se
Tue Dec 9 16:27:56 CET 2003


Hi, 

I do not know of any free TIFF readers for R, so I suggest that you
use an external TIFF-to-Portable Pixmap coverter and then use the
pixmap package available on CRAN. I recommend ImageMagick's convert
program available for Unix, Linux, Windows, Windows/Cygwin etc at
http://www.imagemagick.org/. 

(If you have one already installed, be careful not to work with an old
version; I ran into a problem convert 16-bits TIFF with a 2 years old
convert and it made it only into 8-bit images without warnings. That
should not be a problem now.)

The Portable Pixmap format includes i) RGB images (PPM), gray scale
images (PGM) and monochrome images (PBM). In your case (I assume)
you're working with 16-bits grayscale TIFF images so you should
convert to PGM.

If you have your PATH setup correctly an example would then be:

> library(pixmap)
> system("convert foo.tiff foo.pgm")
> img <- read.pnm("foo.pgm")

and then work from there.

Hope this helps...

Henrik Bengtsson

Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
Lund Institute of Technology/Lund University, Sweden 
(Sweden +1h UTC, Melbourne +11 UTC, Calif. -8h UTC)
+46 708 909208 (cell), +46 46 320 820 (home), 
+1 (508) 464 6644 (global fax),
+46 46 2229611 (off), +46 46 2224623 (dept. fax)
h b @ m a t h s . l t h . s e, http://www.maths.lth.se/~hb/



> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> peter.hagedorn at risoe.dk
> Sent: den 9 december 2003 15:16
> To: r-help at stat.math.ethz.ch
> Subject: [R] Importing TIFF files into a R matrix
> 
> 
> Hi
> 
> I am facing a problem where I would like to import a TIFF 
> image (of spots on a nylon filter) into R (into a matrix for 
> example). When plotting the matrix using fx. scatterplot3d I 
> would then be able to see how the pixel-intensities are 
> distributed in "spot-areas" on the filter - which would be 
> very helpful.
> 
> Does anynone know of a way to do this?
> 
> Best regards,
> 
> Peter Hagedorn
> 
> ...
> Peter Hagedorn
> 
> Risø National Laboratory
> Plant Research Department
> Building PRD-330
> P.O. Box 49
> Frederiksborgvej 399
> DK-4000 Roskilde 
> Denmark
> 
> Phone +45 4677 4293
> Fax     +45 4677 4109
> e-mail  peter.hagedorn at risoe.dk
> web     http://www.risoe.dk/pbk/staff_uk/phah.htm
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://www.stat.math.ethz.ch/mailma> n/listinfo/r-help
> 
>




More information about the R-help mailing list