Python wrapper for OpenJPEG

901 views
Skip to first unread message

Keith Hughitt

unread,
May 9, 2012, 10:31:03 AM5/9/12
to open...@googlegroups.com
Greetings,

I've recently started work on a Python wrapper for OpenJPEG using Cython and wanted to share my progress and get feedback on some possible APIs I'm considering.

So far I've put together a proof of concept which decodes an 8-bit grayscale image into either a bitmap or a NumPy ndarray. The next step will be to decide on an API for the Python library, refactor the code to reflect the desired API, and generalize the decoding support to handle other types of input and output. After that I'll start working on the encoding side, also beginning with some very basic options.

I have a few ideas for the Python API and wanted to see what people thought and if anyone has suggestions:

// Option #1
import openjpeg
decoder = openjpeg.Decoder()
decoder.decode('file.jp2', reduce=2, etc)
decoder.write('file.png')
x = decoder.to_ndarray()

// Option #2
import openjpeg
decoder = openjpeg.Decoder()
im = decoder.decode('file.jp2', reduce=2, etc)
im.write('file.bmp')

// Option #3
import openjpeg
jp2 = openjpeg.JP2Image(...)
jp2.save('file.png')
im = openjpeg.PNGImage(...)
im.encode('file.jp2',...)

I'm open to other suggestions as well. My main goal is to create a fairly simple API so that users can read/write JPEG 2000 files as easily as easily as they could with something like ImageMagick or PIL, while providing the flexibility to access much of the functionality of OpenJPEG.

As soon as I've decided on an API and reworked the code a little I will post it on GitHub so that people can try it and, if interested, contribute.

In the meantime, any feedback is appreciated!

Cheers,
Keith


Mathieu Malaterre

unread,
May 29, 2012, 9:48:27 AM5/29/12
to open...@googlegroups.com
The API you are describing is the simple raster format we usually.
However please keep in mind that JPEG 2000 is meant for handling very
large files. If I were I would have a look at openslide [1] and its
python API to see what is expected for an API when dealing with very
large file.

Thanks for your effort on python-openjpeg !

[1] http://openslide.org/
--
Mathieu

Keith Hughitt

unread,
Jul 18, 2012, 4:52:25 PM7/18/12
to open...@googlegroups.com
Hey all,

Just a quick update - I updated the wrapper to use the OpenJPEG 2.x branch (SVN), and posted the code to Github:


Do not get too excited just yet though - the code I've written so far is in the very early stages of development and really is just a demonstration of the potential to use Cython to create a wrapper for OpenJPEG. The only thing that the module does at the moment is read in a single JP2 image and convert it to a NumPy ndarray:

In [1]: import openjpeg

In [2]: decoder = openjpeg.Decoder()

In [3]: decoder.decode(openjpeg.EIT_IMAGE)

Out[3]: 
array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ..., 
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=uint8)

Some of the next things I want to work on are alternative outputs, sub-region support, XML box retrieval and encoding.

I still haven't settled on an API either, so the above syntax might change in the future.

If anyone is interested in helping, let me know! Feedback is also welcome :)

Cheers,
Keith

On Tuesday, May 29, 2012 9:48:27 AM UTC-4, mathieu wrote:
On Wed, May 9, 2012 at 4:31 PM, Keith Hughittwrote:
Reply all
Reply to author
Forward
0 new messages