What is the easiest way to display a bitmap in R?

I work with TIFF images in R. I load images as

library(tiff) img <- readTIFF("someimage.tiff") 

I am manipulating an img array and want to see the results. One option is to use the writeTIFF function to store the image on disk and open it using the image viewer. However, I want to have an easy way to display images inside R. What would you recommend?

+4
source share
3 answers

here is one option:

 img <- readTIFF(system.file("img", "Rlogo.tiff", package="tiff")) grid::grid.raster(img) 
+5
source

You can do:

 library(raster) b <- brick("someimage.tiff") plotRGB(b) 
+3
source

If you read in tiff as your own raster, you can use the rasterImage() function.

  img = readTIFF('someimage.tiff', native=TRUE) plot(NA,xlim=c(0,nrow(img)),ylim=c(0,ncol(img))) rasterImage(img,0,0,nrow(img),ncol(img)) 

This method works similarly for functions (and corresponding packages): readJPEG, readTIFF, etc.

+1
source

All Articles