[R] fidelity of generated raster images (R and perl)

Martin Maechler maechler at stat.math.ethz.ch
Thu Oct 14 18:08:44 CEST 2004


>>>>> "Scott" == Scott Harrison <harris41 at msu.edu>
>>>>>     on Thu, 14 Oct 2004 11:13:16 -0400 writes:

    Scott> Hi: Goal: use R to turn a matrix of 1's and 0's into
    Scott> a corresponding image (e.g. png) of black and white
    Scott> pixels.

    Scott> Why R: Yes, I can do this more efficiently and
    Scott> precisely with a perl module like Image::PBM.  Been
    Scott> there, done that many times, etc.  (Just humor me.
    Scott> I'm trying to do this with R for a number of
    Scott> reasons.)

    Scott> Problem: Difficult to get a perfect rasterization.
    Scott> There can be appended or removed pixel columns or
    Scott> pixel rows depending on plot region dimensions.  I
    Scott> witness this with both R version 1.8.1 and R version
    Scott> 2.0.

 <....>

    Scott> There are alternatives to rect (plot with type="p",
    Scott> pch=".", etc) and I have also tried png() instead of
    Scott> bitmap().  (I do prefer bitmap so this can run
    Scott> without x11.)

I think the "most typical" alternative is to use  image()
which is probably the most efficient currently --- it is used by
the plot() method of "pixmap" objects in package 'pixmap' {which
you probably should really look at!}.

Note however that image() is still very inefficient for
high-resolution (already 1000x1000) images since it really fills
a rectangular polygon for each pixel.  This e.g. leads to
horribly large postscript files when plotting such pixmaps.

In some way, this is a known "missing feature" in R's graphics
engines.  However a nice implementation would probably use
properties of the graphics device:

A smartImage() function would ``see'' that for a given output
device, it should only draw pixels instead of rects(); even
smarter for even larger pixmaps (where there are less "pixels"
on the output device than you have in your image) it would even average
("color-smooth") neighboring pixmap pixels into device pixels.


    Scott> I am guessing that R's internal region calculations
    Scott> are vector based, which generally makes sense for
    Scott> most statistical plots.  However, I do have some
    Scott> ideas for R and the presentation of cellular automata
    Scott> results.

    Scott> Any tips out there?  (Is it just a matter of
    Scott> height=50px to overcome the inches default,
    Scott> etc?).....

    Scott> Regards, Scott

Regards,
Martin Maechler




More information about the R-help mailing list