user3667217
user3667217

Reputation: 2192

How to decode JPEG XR files in memory using Python

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

Answers (2)

cgohlke
cgohlke

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

svfat
svfat

Reputation: 3363

imageio?

It supports JPEG XR, and can read from can read from filenames, file objects, http, zipfiles, bytes, webcams.

Upvotes: 0

Related Questions