4

I am trying to use python pillow imaging library to process my jp2 images.

I followed these steps:

brew install libjpeg

brew install openjpeg

sudo pip install pillow

I just have problem with .jp2 files. What might be the problem?

Code that I get the error:

from PIL import Image
im = Image.open("sample_1.jp2")
im.show()

I got following error log when I tried to show the image:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 1746, in show
    _show(self, title=title, command=command)

  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 2501, in _show
    _showxv(image, **options)

  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 2506, in _showxv
    ImageShow.show(image, title, **options)

  File "/Library/Python/2.7/site-packages/PIL/ImageShow.py", line 51, in show
    if viewer.show(image, title=title, **options):

  File "/Library/Python/2.7/site-packages/PIL/ImageShow.py", line 77, in show
    return self.show_image(image, **options)

  File "/Library/Python/2.7/site-packages/PIL/ImageShow.py", line 96, in show_image
    return self.show_file(self.save_image(image), **options)

  File "/Library/Python/2.7/site-packages/PIL/ImageShow.py", line 92, in save_image

    return image._dump(format=self.get_format(image))

  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 581, in _dump
    self.load()

  File "/Library/Python/2.7/site-packages/PIL/Jpeg2KImagePlugin.py", line 206, in load

    ImageFile.ImageFile.load(self)

  File "/Library/Python/2.7/site-packages/PIL/ImageFile.py", line 203, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)

  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 420, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)

IOError: decoder jpeg2k not available
user2616232
  • 661
  • 1
  • 9
  • 14
  • You need some kind of JPEG 2000 decoder that will work with this. – user3344003 Sep 28 '15 at 23:13
  • openjpeg is jpeg2000 library. It seems Pillow(PIL) does not see openjpeg while decoding. I do not know how to link them. – user2616232 Sep 29 '15 at 02:38
  • Same problem here, with Python 3. ligjpeg and openjpeg are installed in /usr/local/, but I also get IOError: decoder jpeg2k not available. Working on Mac OS 10.11. Any solution yet? – Nicojo Jan 23 '16 at 16:08

1 Answers1

1

I think I've found the problem...

Pillow installation on Mac OSX states that:

We provide binaries for OS X for each of the supported Python versions in the wheel format. These include support for all optional libraries except OpenJPEG.

I guess the only workaround is to install Pillow from source.

As a side note not directly related to the question, after installing from source, I'm getting a different error:

Nicolas$ python selftest.py
Traceback (most recent call last): 
  File "selftest.py", line 11, in <module>
    from PIL import Image, ImageDraw, ImageFilter, ImageMath
  File "/Users/Nicolas/Downloads/Pillow-3.1.0/PIL/Image.py", line 66, in <module>
    from PIL import _imaging as core
ImportError: cannot import name _imaging

So I do not know if this works yet. Will update if I manage to get it working.

Nicojo
  • 1,043
  • 8
  • 8