有没有人有办法在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文件,到目前为止,这也不是很直接。