20

这似乎很简单,但我无法将 jpeg 或任何类型的图像读入 R 2.15。在 R 2.10 中,我可以使用rimage库或ReadImage库来做到这一点 - 例如使用 read.jpeg - 但在 R 2.15 及更高版本中似乎没有办法做到这一点。对此有什么想法吗?

library('ReadImages') 
Error in library("ReadImages") : there is no package called ‘ReadImages’ > 
install.packages('ReadImages') Installing package(s) into ‘C:/Program Files/R/R-2.15.1/library’ (as ‘lib’ is unspecified) 

Warning in install.packages : package ‘ReadImages’ is not available (for R version 2.15.1) 
4

2 回答 2

39

正如评论中所指出的,请尝试 jpeg 包。

install.packages("jpeg")  ## if necessary

library(jpeg)
## get help
library(help = jpeg)
## get more help
?readJPEG

示例,来自帮助:

# read a sample file (R logo)
img <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))

另一种选择是 rgdal,它可以从大量的格式中读取。绘图和操作的处理方式不同。

install.packages("rgdal") ## if necessary
library(rgdal)
img <- readGDAL(file.path(R.home(), "doc", "html", "logo.jpg"))

CRAN 上还有 readbitmap 包,对于您要查找的内容,始终值得对包列表进行基本搜索。

于 2013-03-09T00:07:36.720 回答
11

还:

## if not already installed
install.packages("jpeg")  

library(jpeg)

?readJPEG()

img <- readJPEG("/Users/name/locationInFileDirectory/image.jpg", native = TRUE)

#this will display your image to test you read it correctly
if(exists("rasterImage")){
      plot(1:2, type='n')
      rasterImage(img,1,1,2,2)
}
于 2015-09-22T00:00:09.077 回答