Reputation: 2192
I'm using Python 3 to process a file produced by microscope, which is essentially a collection of thousands of Jpeg XR compressed images. I need to read all of them into memory. Now I'm reading data in binary mode, saving them in .jxr file and call JxrDecApp.exe to convert it to tiff and read it back to memory. This apparently is a major bottleneck to performance because it involves a lot of file read and write.
From what I gather, ImageMagick also delegates this task to JxrDecApp.exe. So using wand wouldn't help, either. Am I right?
Then I'm wondering if there is any way to decode Jpeg XR in memory using Python?
Upvotes: 3
Views: 2520
Reputation: 9437
Use imagecodecs to decode an in-memory JPEG-XR image to a numpy array:
import imagecodecs
with open('jpegxr.jxr', 'rb') as fh:
jpegxr = fh.read()
numpy_array = imagecodecs.jpegxr_decode(jpegxr)
Works with many other image formats too.
Upvotes: 3