我需要一个例程来使用python读取tiff。我在Working with TIFFs (import, export) in Python using numpy
使用了Michael Brennan的建议import matplotlib
import matplotlib.pyplot as plt
I = plt.imread('ASTGTM_N26E093_num.tif')
print I
我收到运行时错误:未知图像模式
File "img1.py", line 10, in <module>
I = plt.imread('ASTGTM_N26E093_num.tif')
File "/usr/lib64/python2.6/site-packages/matplotlib/image.py", line 776, in imread
im = pilread()
File "/usr/lib64/python2.6/site-packages/matplotlib/image.py", line 767, in pilread
return pil_to_array(image)
File "/usr/lib64/python2.6/site-packages/matplotlib/image.py", line 853, in pil_to_array
raise RuntimeError('Unknown image mode')
RuntimeError: Unknown image mode
有什么建议吗?
答案 0 :(得分:0)
Matplotlib提到PIL是读取多种图像类型的要求。也许您可以尝试安装PIL并再次测试您的代码。
http://matplotlib.org/api/pyplot_api.html?highlight=imread#matplotlib.pyplot.imread
答案 1 :(得分:0)
尝试pylibtiff,它对我来说有一堆tiff图像,其中matplotlib或PIL失败。从他们的帮助:
from libtiff import TIFF
# to open a tiff file for reading:
tif = TIFF.open('filename.tif', mode='r')
# to read an image in the currect TIFF directory and return it as numpy array:
image = tif.read_image()
# to read all images in a TIFF file:
for image in tif.iter_images(): # do stuff with image
# to open a tiff file for writing:
tif = TIFF.open('filename.tif', mode='w')
# to write a image to tiff file
tif.write_image(image)