RBioFormats icon indicating copy to clipboard operation
RBioFormats copied to clipboard

read.image failing for very large images

Open rossholmberg opened this issue 9 years ago • 6 comments

For images with large pixel counts (eg: 8E8 pixels), read.image returns an error, even when trying to return a small subset of the image area.

img <- RBioFormats::read.image(filename, subset = list(X=10000:10200, Y=20000:20100))

Error in .jcall(reader, "I", "getSeriesCount") : java.lang.IllegalArgumentException: Array size > Integer.MAX_VALUE!

Seems to be a limitation of the integer class itself, which maxes out at less than 3E8. Changing "I" classes to "J" throughout read.image.R doesn't help though.

rossholmberg avatar Nov 16 '16 11:11 rossholmberg

Thanks for reporting this and for looking into it! I'm not entirely sure though whether the problem lies in the code of my package. In principle, for a single JPEG file the getSeriesCount Java method should just return 1L, therefore I'm a bit puzzled by the error. There might be something funny about this particular image file itself.

aoles avatar Nov 16 '16 11:11 aoles

It seems that indeed there is a problem with the original .jpeg file. After converting it to TIFF with the ImageMagick convert tool I was able to successfully run the example posted at Stack Overflow.

aoles avatar Nov 16 '16 12:11 aoles

Interesting, you're right. That jpg was created with ImageMagick though, so I was curious. I converted it to tif as suggested, and it works. Convert it back to jpg again as a new file, and we get the same error again. Could it be a problem only with jpg format?

rossholmberg avatar Nov 16 '16 12:11 rossholmberg

Not with JPEG in general, as for example, the following works just fine.

filename <- system.file("img", "Rlogo.jpg", package="jpeg")

coreMetadata(read.metadata(filename))$series
## [1] 1

aoles avatar Nov 16 '16 12:11 aoles

Sorry, I still mean for very large pixel sizes, but perhaps only when that (very large) image is jpg?

rossholmberg avatar Nov 16 '16 13:11 rossholmberg

Hi, chiming in late but I would to cross-reference this issue with the one reported upstream. Shortly, there is a known limitation/bug during the initialization of very large JPEG files. Although the description does not include the full stack trace, it sounds like a similar issue.

sbesson avatar May 08 '17 19:05 sbesson