Read/Write Portable Anymap Images
Reading and writing of bitmap images in PBM (black/white), PGM (grey) and PPM (color) format.
read.pnm(file, ...) write.pnm(object, file= NULL, forceplain = FALSE, type = NULL, maxval = 255)
- name of the pnm file (general
connectionsdo not work at the moment).
- further arguments passed to
- an object of class
- logical; if true, an ASCII pnm file is written. Default is to write a binary (raw) file.
- one of
"ppm". Default is to use
"pgm"for grey images and
"ppm"for color images.
- the maximum color-component value; the default is a colour depth of 8 bits, i.e., the integer 255.
read.pnm reads a pnm file and loads the image into an
object of class
write.pnm writes an object of class
pixmap to a
pnm file, the
type argument controls wheter the written image
file is a black-and-white bitmap (pbm), grey (pgm) or color (ppm).
plot.pnm plots a pnm object using the command
image. The only difference is that the element
pnmobj is plotted as the upper left corner (plain
image would plot
[1,1] as the lower left corner.
read.pnmreturns an object of class
pixmapRGBfor color pixmaps (ppm), and an object of class
pixmapGreyfor pbm and pgm. Note that the type of file as determined by the first two bytes according to pnm standards is important, not the extension of the file. In fact, the file name extension is completely ignored.
x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")) plot(x) print(x) x <- read.pnm(system.file("pictures/logo.pgm", package="pixmap")) plot(x) x <- read.pnm(system.file("pictures/logo.pbm", package="pixmap")) plot(x)