hlin117
hlin117

Reputation: 22268

Displaying images in R in version 3.1.0

I've ran into old stackoverflow posts like this one that use packages like ReadImages and biOps that are now deprecated in R 3.1.0, and are not available anymore.

Can someone tell me how to display an image in R 3.1.0? (Specifically jpeg and png images)

Upvotes: 16

Views: 33278

Answers (2)

Ben Bolker
Ben Bolker

Reputation: 226522

As pointed out by Simon Urbanek in the comments of the linked question, you can do this:

library("jpeg")
jj <- readJPEG("myfile.jpg",native=TRUE)
plot(0:1,0:1,type="n",ann=FALSE,axes=FALSE)
rasterImage(jj,0,0,1,1)

or (for PNG)

library("png")
pp <- readPNG("myfile.png")
plot.new() 
rasterImage(pp,0,0,1,1)

version 0.1.7 of png, 0.1.8 of jpeg

Upvotes: 22

Vincent
Vincent

Reputation: 353

The package imager can load png, jpeg and bmp images.

library(imager)
im<-load.image("myimage")
plot(im)

It has also many functions for processing and plotting. With extra libraries installed (ffmpeg and ImageMagick), it can even load videos and other images format.

Upvotes: 19

Related Questions