Hi, I dont think you can import PNG images into R directly (although I may be wrong). I use ImageMagick (available for most operating systems) and the system() function to do my image conversions. convertImage<-function(dirname,srcname,targetname){ strSrcName<-shQuote(paste(dirname,srcname,sep='/')) strTrgName<-shQuote(paste(dirname,targetname,sep='/')) filelist<-system(paste('ls',strSrcName,sep=' '),TRUE,TRUE) if(length(filelist)<1){ stop("Source Image Not Found") } filelist<-system(paste('ls',strTrgName,sep=' '),TRUE,TRUE) if(length(filelist)<1){ strcmd<-paste('convert',strSrcName,strTrgName,sep=' ') system(strcmd) } } On Mon, 2005-21-11 at 11:36 +0100, Sydler, Dominik wrote:> Hi there > > I'm looking for a function to read PNG-bitmap-images from a file into R. > I only found: > - the pixmap-package which cannot import png or similar formats > - the rimage-package which can only import lossy jpeg-images (the > convertion from png to jpeg modifies the data!) > > Is there any possibility to read PNG-files? > > Thanks for any help > Dominic Sydler > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Hi there I'm looking for a function to read PNG-bitmap-images from a file into R. I only found: - the pixmap-package which cannot import png or similar formats - the rimage-package which can only import lossy jpeg-images (the convertion from png to jpeg modifies the data!) Is there any possibility to read PNG-files? Thanks for any help Dominic Sydler
I was looking once for all supported image formats, here is what I found: Format | read file to matrix | write matrix to file | write plot to file -------|---------------------|----------------------|------------------- PNG | | | png, bitmap, GDD JPEG | read.jpeg | | jpeg, bitmap, GDD GIF | read.gif | write.gif | GDD TIFF | read.picture | write.picture | savetiff, bitmap PDF | | | pdf, bitmap ENVI | read.ENVI | write.ENVI | ? | read.pnm | write.pnm | I have not played with every one of those functions and I think that every read/write returns "matrix" in some other internal format. Also, last 2 formats are rather exotic and of limited use. Use CRAN search to look up package of each function. So I think that in your case your best bet would be to convert your file to GIF (if you can live with only 256 colors) or TIFF. Also does anybody know how hard would it be to tap into C code needed for 'read.jpeg', 'png' and 'jpeg' functions to write 'read.png' , 'write.png', and 'write.jpeg' functions? Jarek Tuszynski -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Sydler, Dominik Sent: Monday, November 21, 2005 5:36 AM To: r-help at stat.math.ethz.ch Subject: [R] PNG-import into R Hi there I'm looking for a function to read PNG-bitmap-images from a file into R. I only found: - the pixmap-package which cannot import png or similar formats - the rimage-package which can only import lossy jpeg-images (the convertion from png to jpeg modifies the data!) Is there any possibility to read PNG-files? Thanks for any help Dominic Sydler ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Mon, 21 Nov 2005, Sydler, Dominik wrote:> Hi there > > I'm looking for a function to read PNG-bitmap-images from a file into R. > I only found: > - the pixmap-package which cannot import png or similar formats > - the rimage-package which can only import lossy jpeg-images (the > convertion from png to jpeg modifies the data!) > > Is there any possibility to read PNG-files?Under Linux, install GDAL directly then package rgdal from source, I guess some variant of this under OSX. Under Windows, install the rgdal binary package from Prof. Ripley's repository - for me:> options("repos")$repos CRAN CRANextra "@CRAN@" "http://www.stats.ox.ac.uk/pub/RWin" or download from: http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.2/ directly. Then:> x.png <- GDAL.open(file.choose()) > getDriverLongName(getDriver(x.png))[1] "Portable Network Graphics">From there you use getRasterData() on the bands and subscenes you want,GDAL.open() just returns a file handle, letting you choose the parts you need. That is probably the least resistance path.> > Thanks for any help > Dominic Sydler > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Reasonably Related Threads
- display SVG, PNG, GIF, JPEG, TIFF, PPM in new plot frame
- R CMD BATCH: unable to start device PNG
- Bug using X11 on mac osx (for jpeg or png creation) (PR#10800)
- converting a vector of bytes to a PNG/JPEG image
- [Rdev] any way to generate "bitmap" (tif, jpeg, png etc) files in R CMD BATCH