s-u / jpeg Goto Github PK
View Code? Open in Web Editor NEWRead and write JPEG images in R
Read and write JPEG images in R
Hi Simon,
I've been struggling with images that are "partially corrupted" - that is, part of the image is cut off by a large black or grey area (see example image, here). If I run "readJPEG" on this image like this:
img <- readJPEG("2017-08-30 00-17-42 M 1_5.JPG")
the output is:
JPEG decompression: Corrupt JPEG data: premature end of data segment
.
As far as I can tell, this "message" is not actually a message or a warning, which makes it really difficult to do error checking or to capture that message or warning (for example, in tryCatch
). For a more fulsome explanation of why this is troublesome, consider my question at stack overflow (here), if you're interested.
In any case, is it possible to change the function (or provide a similar one, like readJPEG2
) that outputs that explanatory text as a message or warning?
Checked on
The jpeg lib is installed and linked via homebrew.
install.packages("jpeg", type = "source")
#> Installing package into '/Users/pjs/Library/R/4.0/library'
#> (as 'lib' is unspecified)
* installing *source* package ‘jpeg’ ...
** package ‘jpeg’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
ccache clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -fPIC -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c read.c -o read.o
In file included from read.c:1:
./rjcommon.h:11:10: fatal error: 'jpeglib.h' file not found
#include <jpeglib.h>
^~~~~~~~~~~
1 error generated.
make: *** [read.o] Error 1
ERROR: compilation failed for package ‘jpeg’
* removing ‘/Users/pjs/Library/R/4.0/library/jpeg’
* restoring previous ‘/Users/pjs/Library/R/4.0/library/jpeg’
The downloaded source packages are in
‘/private/var/folders/w5/1wdhg7nd4zj7td7_pkgrl4fm0000gn/T/RtmpQjlll2/downloaded_packages’
Warning message:
In install.packages("jpeg", type = "source") :
Created on 2020-04-13 by the reprex package (v0.3.0)
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.0 beta (2020-04-12 r78209)
#> os macOS Catalina 10.15.4
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Berlin
#> date 2020-04-13
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
#> backports 1.1.6 2020-04-05 [1] CRAN (R 4.0.0)
#> callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0)
#> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0)
#> devtools 2.3.0 2020-04-10 [1] CRAN (R 4.0.0)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 4.0.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0)
#> fs 1.4.1 2020-04-04 [1] CRAN (R 4.0.0)
#> glue 1.4.0 2020-04-03 [1] CRAN (R 4.0.0)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.0)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 4.0.0)
#> knitr 1.28 2020-02-06 [1] CRAN (R 4.0.0)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.0)
#> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 4.0.0)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 4.0.0)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
#> processx 3.4.2 2020-02-09 [1] CRAN (R 4.0.0)
#> ps 1.3.2 2020-02-13 [1] CRAN (R 4.0.0)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0)
#> Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0)
#> remotes 2.1.1 2020-02-15 [1] CRAN (R 4.0.0)
#> rlang 0.4.5 2020-03-01 [1] CRAN (R 4.0.0)
#> rmarkdown 2.1 2020-01-20 [1] CRAN (R 4.0.0)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.0)
#> testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0)
#> usethis 1.6.0 2020-04-09 [1] CRAN (R 4.0.0)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 4.0.0)
#> xfun 0.13 2020-04-13 [1] CRAN (R 4.0.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
#>
#> [1] /Users/pjs/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
And get the following errors
Will be glad to know how to fix it
Hi,
I'm just trying to download the package in RStudio and having mega issues. I even uninstalled R and RStudio and brought them back but to no avail. Here's what I'm getting in the console when I try to install. If there's anything I'm doing wrong, please let me know. Thanks
(as ‘lib’ is unspecified)
trying URL 'http://rforge.net/src/contrib/jpeg_0.1-9.tar.gz'
Content type 'application/x-gzip' length 18097 bytes (17 KB)
downloaded 17 KB
* installing *source* package 'jpeg' ...
** using staged installation
checking JPEG headers and libraries
LOCAL_SOFT does not exist, fall back to external jpeg
cannot find current JPEG files
attempting to download them
Error in download.file("http://www.rforge.net/jpeg/files/libjpeg-current-win.tar.gz", :
cannot open destfile 'src/libjpeg-current-win.tar.gz', reason 'No such file or directory'
Execution halted
*** ERROR: unable to find JPEG files
They must be either in src/win32, in a tar-ball
src/libjpeg-current-win.tar.gz or
available via the LOCAL_SOFT R make setting.
You can get the latest binary tar ball from
http://www.rforge.net/jpeg/files/
ERROR: configuration failed for package 'jpeg'
* removing 'C:/Users/MadisonDC/Documents/R/win-library/4.1/jpeg'
Warning in install.packages :
installation of package ‘jpeg’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\MadisonDC\AppData\Local\Temp\RtmpctQ5UI\downloaded_packages’
I don't think this has been documented, so just wanted to share installation instructions if libjpeg is installed in a non-standard location, on Linux at least. Enter something like the following in the shell:
export JPEG_CFLAGS=-I/path/to/libjpeg/include
export JPEG_LIBS=-L/path/to/libjpeg/lib
Make sure to substitute the libjpeg installation path.
Then within R, install the jpeg package like normal.
Hi, I am trying to install by compiling from source on R 4.0.3 on BigSur 11.2 and get this error:
ld: library not found for -ljpeg
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [qpdf.so] Error 1
ERROR: compilation failed for package `‘qpdf’```
I have libjpeg 9d installed via Homebrew. I tried to reinstall and re-start R with no success. No matter what, the error persists. Any suggestions? Thanks
I have two cat images, one in high format and one in landscape format (https://www.dropbox.com/sh/7xa9jfxlsr6wy5s/AABVZJO0GrwvuVb9qryJjCG7a?dl=0). When I read them with readJPEG
the dimensions for both are the same:
jpg1 <- readJPEG("/Volumes/Vero/Data/Animals/Cat/20150805_172829743_iOS.jpg")
jpg2 <- readJPEG("/Volumes/Vero/Data/Animals/Cat/20150808_183100413_iOS.jpg")
str(jpg1)
str(jpg2)
The last two lines both print num [1:2448, 1:3264, 1:3] 0.996 0.996 0.996 0.996 0.996 ...
although the first (high format) should be [1:3264 1:2448 1:3]. When I save them again with writeJPEG
the landscape one looks normal (although its larger than before) and the other one is mixed up (it's rather large so I don't upload it except you would like me to).
After using jpg1_a <- aperm(jpg1, c(2, 1, 3))
and writing the image it looks normal but rotated.
Is there something wrong with the library or is it a problem with my image? (I have encountered that some other programs also have problems with photos taken by an iPhone).
Best regards,
Verena
EDIT: I looked a little further and found out that the rotation would be in the exif data (1 for "normal" and 6 for "rotated"), e.g. explained here. [http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/](EXIF orientation handling is a ghetto). I'm trying to figure out a way based on the [https://github.com/ironholds/exif](exif meta data) to handle my images correctly. I don't know if you will/want to include this information in your package.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.