Python:读写TIFF 16位,三 channel ,彩色图像

标签 python image numpy png tiff

有没有人有在 Python 中导入每 channel 16 位、3 channel TIFF 图像的方法?

我还没有找到一种在处理 TIFF 格式时可以保留每个 channel 16 位深度的方法。我希望一些有帮助的人能找到解决办法。

以下是我迄今为止尝试过但没有成功的方法和结果:

import numpy as np
import PIL.Image as Image
import libtiff
import cv2

im = Image.open('a.tif')
# IOError: cannot identify image file

tif = libtiff.TIFF.open('a.tif')
im = tif.read_image()
# im only contains one of the three channels. im.dtype is uint16 as desired.
im = []
for i in tif.iter_images():
    # still only returns one channel

im = np.array(cv2.imread('a.tif'))
# im.dtype is uint8 and not uint16 as desired.
# specifying dtype as uint16 does not correct this

到目前为止,我发现的唯一解决方案是使用 ImageMagick 将图像转换为 PNG。然后沼泽标准 matplotlib.pyplot.imread 读取 PNG 文件没有任何问题。

我遇到的另一个问题是将任何 numpy 数组保存为 16 位 PNG 文件,到目前为止这也不是很简单。

最佳答案

它的功能有限,尤其是在将非 RGB 图像回写到磁盘时,但是 Christoph Gohlke's tifffile module读取 3 channel 16 位 TIFF 没有问题,我刚刚测试过:

>>> import tifffile as tiff
>>> a = tiff.imread('Untitled-1.tif')
>>> a.shape
(100L, 100L, 3L)
>>> a.dtype
dtype('uint16')

而且 Photoshop 阅读时不会提示我所做的事情:

>>> tiff.imsave('new.tiff', a)

关于Python:读写TIFF 16位,三 channel ,彩色图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18446804/

相关文章:

html - 内联图像和 h (HTML/CSS)

python - 更改 numpy 结构化数组 dtype 名称和格式

python - 如何将 RGB 图像转换为 numpy 数组?

python - 在 PyTables 中存储和提取 numpy 日期时间

html - 额外的 div 导致图像高度无法正确缩放(显示 : flex)

python - 如果模式中任何位置都有字符,则正则表达式不匹配

python - 选择组合框值后获取字典的值

python - 为什么 pandas df.plot.bar() 不接受宽度数组?

python - Pandas 在数据框中的两列中查找交叉销售

html - 图片托管和 HTML img 链接