Hi all, is there any R function that loads a bmp file, or any other format, and converts its grid of pixels into a matrix or data frame? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000628/f3fc8b21/attachment.html
BMP to matrix
7 messages · Manuel Castejón Limas, Ben Bolker, Brian Ripley +1 more
Try the pnm() function in the e1071 library (can't remember if it's included by default, you may have to grab it from CRAN)
On Wed, 28 Jun 2000, Manuel Castejon Limas wrote:
Hi all, is there any R function that loads a bmp file, or any other format, and converts its grid of pixels into a matrix or data frame? Thanks in advance.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 28 Jun 2000, Manuel Castejon Limas wrote:
Hi all, is there any R function that loads a bmp file, or any other format, and converts its grid of pixels into a matrix or data frame?
Almost certainly not (they are binary files) but netpbm and ImageMagick and such programs have means to convert the files to an ASCII gird of numbers, which R can read easily. That's mainly how we do it. For really big image files, I wrote a C interface that reads the file and fills a pre-allocated array.
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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 28 Jun 2000 19:50:36 +0100 (BST), Prof Brian D Ripley <ripley at stats.ox.ac.uk> wrote in message <Pine.GSO.4.05.10006281948310.23872-100000 at auk.stats>:
On Wed, 28 Jun 2000, Manuel Castejon Limas wrote:
is there any R function that loads a bmp file, or any other format, and converts its grid of pixels into a matrix or data frame?
Almost certainly not (they are binary files) ...
Is there a reason why R doesn't read binary files, or is it just that nobody has volunteered to write functions for that yet? Duncan Murdoch -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 28 Jun 2000, Duncan Murdoch wrote:
On Wed, 28 Jun 2000 19:50:36 +0100 (BST), Prof Brian D Ripley <ripley at stats.ox.ac.uk> wrote in message <Pine.GSO.4.05.10006281948310.23872-100000 at auk.stats>:
On Wed, 28 Jun 2000, Manuel Castejon Limas wrote:
is there any R function that loads a bmp file, or any other format, and converts its grid of pixels into a matrix or data frame?
Almost certainly not (they are binary files) ...
Is there a reason why R doesn't read binary files, or is it just that nobody has volunteered to write functions for that yet?
What do you read them into? Svr4 has a `raw' data type, but R has no such type, and S-PLUS 5.x has almost no support for it. Without, say, 8-bit, 16-bit and 32-bit unsigned data types and some useful operators on them, it is hard to do much usefully at the R level. There has not been the need when usually one can borrow and interface tested C code.
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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 28 Jun 2000 20:18:24 +0100 (BST), you wrote in message <Pine.GSO.4.05.10006282014180.12878-100000 at auk.stats>:
On Wed, 28 Jun 2000, Duncan Murdoch wrote:
Is there a reason why R doesn't read binary files, or is it just that nobody has volunteered to write functions for that yet?
What do you read them into? Svr4 has a `raw' data type, but R has no such type, and S-PLUS 5.x has almost no support for it. Without, say, 8-bit, 16-bit and 32-bit unsigned data types and some useful operators on them, it is hard to do much usefully at the R level. There has not been the need when usually one can borrow and interface tested C code.
I think a set of stream like functions would be really handy sometimes, especially for those of us who aren't that comfortable with the external function interface. For example: fopen would take a filename and some information about the open mode (read and write would probably be enough modes) and would return a file handle. readint8, readint16, readint32, readint64 would read a specified count of integers into an integer vector. readfloat4, readfloat8 would read a specified count of floating point values into a vector of doubles. readchar would read a specified count of characters into a single component character vector, or take two counts, and read n characters m times into an m component vector. There would be similar writexxxx functions, a seek function, and an fclose function. Some issues to consider would be whether these functions should worry about big vs. little endian storage (I'd say probably not, but there should be other functions that can change it in memory), how errors should be handled, whether the garbage collector should be smart enough to automatically close an abandoned file, whether you should be allowed to use these low level functions on things in memory or just on files, etc. Duncan Murdoch -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I really appreciate your incoming messages. Thanks a lot for the information about the image loading procedures. They will be of great help. Manuel. -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000629/368c7324/attachment.html