I am interested in converting a matrix to an image (element value = pixel intensity), a bit like:
R – image of a pixel matrix?
However I need the size of the image to be exactly (in pixels) the size of the matrix. So if the matrix is 234×14 so should be the generated image.
Preference for a solution using no additional R package (like in answer to question lined above), but everything would be fine as well.
One way is to avoid the R devices completely, and rely on the GDAL drivers in
rgdal.There are other drivers in GDAL, but “GeoTIFF” is the default, and the defaults will preserve the values accurately (within the numeric limits of R and GDAL). This is just a single band raster, but it will work the same for multiple attributes.
The real limit here is the target you have for the file, and whether it can read the resulting image in the way that you want. GDAL has all the options you would need, but whether the defaults are right and what you really need depends on details.
Here is a floating point example that shows the numeric limits more realistically:
Another way is the pnm format that is used by
pixmap. See