在Python Pillow中处理JP2图像

4

我试图使用Python pillow图像处理库来处理我的jp2图像。

我按照以下步骤进行操作:

brew install libjpeg

brew install openjpeg

sudo pip install pillow

我只有在处理.jp2文件时遇到问题。可能是什么问题?

引起错误的代码:

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

当我尝试显示图片时,出现了以下错误日志:
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

你需要一种能够与此兼容的JPEG 2000解码器。 - user3344003
openjpeg是jpeg2000库。似乎Pillow(PIL)在解码时无法识别openjpeg。我不知道如何将它们链接起来。 - user2616232
这里也有同样的问题,使用Python 3。ligjpeg和openjpeg已经安装在/usr/local/中,但我仍然遇到IOError: decoder jpeg2k not available。我正在使用Mac OS 10.11。是否已经有解决方案了? - Nicojo
1个回答

1

我想我已经找到了问题所在...

在Mac OSX上安装Pillow指出:

我们为每个受支持的Python版本提供OS X的二进制文件,以wheel格式提供。这些包括对除OpenJPEG之外的所有可选库的支持。

我想唯一的解决方法是从源代码安装Pillow。

顺便提一下,与问题不直接相关的是,在从源代码安装后,我遇到了一个不同的错误:

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

所以我不知道这是否有效。如果我成功让它工作,我会更新的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接