6

I'm working with TIFF images in R. I load images as

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

I'm manipulating with img array then and want to see the results. One of the options is use writeTIFF function to store the image on the disk and open it with an image viewer. However I wish to have some simple way to display images inside R. What would you recommend?

3
  • From which package comes readTIFF? Also, isn't plot(img) working?
    – user3710546
    Aug 7, 2015 at 7:59
  • Have a look at rasterImage Aug 7, 2015 at 8:01
  • @Pascal readTIFF comes from tiff package. plot(img) works... well, sort of. It's not showing the image, but vectors coordinates instead.
    – avli
    Aug 7, 2015 at 8:06

3 Answers 3

9

here's one option:

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

You can do:

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

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

 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 the functions (and corresponding packages): readJPEG, readTIFF, etc...

2
  • 1
    That example does not use any functions from the raster package (I added an answer that does). Aug 9, 2016 at 7:45
  • Wow, good catch. I have edited my answer according to your comment. Cheers! Aug 9, 2016 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.