我正在尝试访问存储在tiff文件中的温度数据。向我提供了一个应该能够做到这一点的python脚本,但我一直收到以下错误:
Traceback (most recent call last):
File "read_tiff.py", line 57, in <module>
im = Image.open(sourcePath)
File "/Users/myname/opt/anaconda3/lib/python3.8/site-packages/PIL/Image.py", line 2943, in open
raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file 'Testbild.tiff'
这是守则的有关部分:
sourcePath = "Testbild.tiff"
im = []
try:
sourcePath = sys.argv[1]
except IndexError:
print('usage: python read_tiff.py filename')
sys.exit()
try:
im = Image.open(sourcePath)
except FileNotFoundError:
print('File not found: ' + sourcePath)
sys.exit()
imarray = np.array(im)
这是我查过的:
。
有人能帮我吗?
干杯!
编辑:图像的导入语句是from PIL import Image
如果有必要,这些是脚本的所有导入语句:
import matplotlib.pyplot as plt
from PIL import Image
import sys
import numpy as np
import math
import cv2
发布于 2020-12-18 10:41:54
试着使用:
from skimage import io
im = io.imread(sourcePath)
这将直接打开它作为一个数组。
发布于 2021-08-08 12:01:53
在我的例子中,它可以将.tif
文件读取到ndarray
。
path2dir = r'C:\data\WORK\image4example'
name_img = 'Slice_25.tif'
path2img = os.path.join(path2dir, name_img)
im = cv2.imread(path2img , cv2.IMREAD_ANYDEPTH)
plt.imshow(im)
https://stackoverflow.com/questions/65347576
复制相似问题