Hoo*_*usX 20 import png jpeg r
这看起来非常微不足道,但我无法用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)
Run Code Online (Sandbox Code Playgroud)
mds*_*ner 38
正如评论中指出的那样,试试jpeg包.
install.packages("jpeg") ## if necessary
library(jpeg)
## get help
library(help = jpeg)
## get more help
?readJPEG
Run Code Online (Sandbox Code Playgroud)
例如,来自帮助:
# read a sample file (R logo)
img <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))
Run Code Online (Sandbox Code Playgroud)
另一种选择是rgdal,它可以从大量的格式中读取.绘图和操作的处理方式不同.
install.packages("rgdal") ## if necessary
library(rgdal)
img <- readGDAL(file.path(R.home(), "doc", "html", "logo.jpg"))
Run Code Online (Sandbox Code Playgroud)
在CRAN上还有readbitmap包,总是值得基本搜索包列表以寻找你想要的东西.
小智 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)
}
Run Code Online (Sandbox Code Playgroud)