3

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?

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
user3667217
  • 2,172
  • 2
  • 17
  • 29

2 Answers2

2

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.

cgohlke
  • 9,142
  • 2
  • 33
  • 36
0

imageio?

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

svfat
  • 3,273
  • 1
  • 15
  • 34
  • Thanks for the input. The documentation isn't clear on how to perform image conversion. The example on how to convert color video into grayscale video is simply taking the first channel of the color video, which seems to be a very odd way to me and makes me wonder how useful this library will be. Could you provide any example code? – user3667217 Aug 16 '15 at 19:48
  • @user3667217 maybe you can find something in [the source code of the library](https://github.com/imageio/imageio/blob/master/imageio/core/functions.py) . Looks like it well-documented. I think you should use `imread` and `imwrite` functions – svfat Aug 17 '15 at 05:03
  • 2
    This didn't work for me: `im = imageio.imread('some.jxr', format='JPEG-XR')` on linux, despite JxrDecApp and ImageMagick's convert being able to convert the jxr to a tif. – fpghost Sep 08 '15 at 02:10
  • 2
    Are you using Debian or Ubuntu? imageio uses the freeimage library, and Debian introduced a bug in their package. Wasted a day of my life too... http://git.net/ml/general/2016-10/msg21901.html – dividebyzero Jan 24 '17 at 15:47