有没有人有在 Python 中导入每通道 16 位、3 通道 TIFF 图像的方法?
在处理 TIFF 格式时,我还没有找到一种可以保留每个通道 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 文件,到目前为止这也不是很简单。