how to read.jpeg in R 2.15

后端 未结 2 1749
小鲜肉
小鲜肉 2020-12-08 07:50

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 librar

相关标签:
2条回答
  • 2020-12-08 08:29

    As pointed out in comments, try the jpeg package.

    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.

    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.

    0 讨论(0)
  • 2020-12-08 08:32

    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)
    }
    
    0 讨论(0)
提交回复
热议问题