有人有导入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文件,这也迄今为止并不简单。