Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read.jpeg in R 2.15

Tags:

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?

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) 
like image 211
HoofarLotusX Avatar asked Mar 07 '13 22:03

HoofarLotusX


People also ask

How do I view a JPEG file?

You can open JPG files with your web browser, like Chrome or Firefox (drag local JPG files onto the browser window), and built-in Microsoft programs like the photo viewer and Paint application. If you're on a Mac, Apple Preview and Apple Photos can open the JPG file.

What encoding is used for JPG?

JPEG compression. JPEG uses a lossy form of compression based on the discrete cosine transform (DCT). This mathematical operation converts each frame/field of the video source from the spatial (2D) domain into the frequency domain (a.k.a. transform domain).


1 Answers

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.

like image 157
mdsumner Avatar answered Sep 17 '22 12:09

mdsumner