如何在Windows上安装OpenJPEG并将其与Pillow结合使用? [英] How do I install OpenJPEG on Windows and use it with Pillow?

查看:429
本文介绍了如何在Windows上安装OpenJPEG并将其与Pillow结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python Pillow库以jp2("JPEG 2000")格式保存16位灰度级数组.

I would like to use the Python Pillow library to save 16 bit gray scale arrays in the jp2 ("JPEG 2000") format.

在尝试在Windows计算机上安装所需的库OpenJPEG时遇到了麻烦. 文档不太清楚...但是我认为我需要下载Win64二进制文件,然后将它们放在我的路径上(我这样做了).

I have hit a brick wall in trying to install the required library OpenJPEG on my Windows machine. The documentation is not very clear... but I assumed that I needed to download the Win64 binaries and simply put them on my path ( which I did).

这样做,在Windows的Anaconda 4.3.0中使用Pillow 4.0.0时,仍然出现以下错误.

That done, I am still getting the following error when using Pillow 4.0.0 in Anaconda 4.3.0 on Windows.

IOError: encoder jpeg2k not available

任何人都成功地使用Pillow来读写JPEG 2000文件,我肯定会喜欢一些技巧.

Anyone out there successfully used Pillow to write and read JPEG 2000 files, I would sure appreciate some tips.

以下是失败的代码:

import PIL
import numpy as np

arr = np.ones(dtype=np.uint16, shape=(100, 100))
im = PIL.Image.fromarray(arr)
im.save('arr.jp2')

推荐答案

我刚刚使用来自此处.我选择了Pillow-4.0.0.win-amd64-py3.5.exe.在安装过程中,它发现了conda的python,并正确选择了安装位置(安装在根环境中).

I've just installed Pillow with an installer from here. I chose Pillow-4.0.0.win-amd64-py3.5.exe. During install it found conda's python and properly chose where to install (it installed to a root environment).

代码进行测试:

from PIL import Image
import numpy as np
arr = np.ones(dtype=np.uint16, shape=(100,100))
im = Image.fromarray(arr)
im.save('test.jp2') 

请注意,保存的文件的速度为8 bpp.

Note, that saved file has 8 bpp.

这篇关于如何在Windows上安装OpenJPEG并将其与Pillow结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆