如何在R 2.15中读取.jpeg

时间:2022-11-25 21:19:16

It seems very trivial but I can't read in jpeg, or any type of image into R 2.15. In R 2.10 I could do it using rimage library or ReadImage library - with read.jpeg for example - but there seems to be no way to do it in R 2.15 and later versions. Any thoughts on this?

这看起来非常微不足道,但我无法用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) 

2 个解决方案

#1


33  

As pointed out in comments, try the jpeg package.

正如评论中指出的那样,试试jpeg包。

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

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

Example, from the help:

例如,从帮助:

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

Another option is rgdal, which can read from a massive bestiary of formats. Plotting and manipulation are handled differently.

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

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

There is also the readbitmap package on CRAN, it's always worth a basic search of the packages list for what you are looking for.

在CRAN上还有readbitmap包,总是值得基本搜索包列表以寻找你想要的东西。

#2


9  

also:

也:

## 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)
}

#1


33  

As pointed out in comments, try the jpeg package.

正如评论中指出的那样,试试jpeg包。

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

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

Example, from the help:

例如,从帮助:

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

Another option is rgdal, which can read from a massive bestiary of formats. Plotting and manipulation are handled differently.

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

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

There is also the readbitmap package on CRAN, it's always worth a basic search of the packages list for what you are looking for.

在CRAN上还有readbitmap包,总是值得基本搜索包列表以寻找你想要的东西。

#2


9  

also:

也:

## 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)
}