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

Scott Harrison harris41 at msu.edu
Thu Oct 14 17:13:16 CEST 2004


Hi:

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

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

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

print($out "bitmap('/usr/local/mycrow/tmp/out.png', type = 'png256', 
height = ".(int($height*68/64)/64).", width = 
".(int($width*69/64)/64).", res = 64, pointsize=0)\n");
print($out 'par(mar=c(0,0,0,0))'."\n");
my $width1 = $width-1;
my $height1 = $height-1;
print($out <<END);
plot.new()
plot.window(c(0,$width1),c(0,$height1))
rect(m[,1], m[,2], m[,1], m[,2], col="black", border="black")

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

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

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

Regards,
Scott




More information about the R-help mailing list