有没有一种方法可以在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。然后bog标准matplotlib.pyplot.imread读取PNG文件,没有任何问题。
我遇到的另一个问题是将任何numpy数组保存为16位PNG文件,到目前为止这也不是一个简单的问题。