How to resolve TiffFileError: Not a Tiff File and Byte Problem with KeyError: b'\x89P'

How to resolve TiffFileError: Not a Tiff File and Byte Problem with KeyError: b'\x89P'

我正在建立一个计算机视觉项目来检测和处理 GFP 蛋白。我不断收到关于我的文件不是 Tiff 图像和字节错误的错误。我不太明白他们的意思,也没有在网上找到任何相关信息。

我已经确定文件路径是正确的,并尝试将文件更改为Tiff格式。现在在 Finder 上,它说它是一个 TIFF 图像,但仍然给出错误。

import tifffile
from colicoords import Data, Cell, CellPlot
import matplotlib.pyplot as plt


binary_img = tifffile.imread('organoid_images/gfp/cells1.tif')
data = Data()
data.add_data(binary_img, 'binary')
cell = Cell(data)
cell.optimize()
cp = CellPlot(cell)

plt.figure()
cp.imshow('flu_514', cmap='viridis', interpolation='nearest')
cp.plot_outline()
cp.plot_midline()
plt.show()

错误信息:

Traceback (most recent call last):
  File "/Users/CosmoCrash/opencvblobs/lib/python3.7/site-packages/tifffile/tifffile.py", line 2236, in __init__
    byteorder = {b'II': '<', b'MM': '>'}[header[:2]]
KeyError: b'\x89P'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "gfp.py", line 6, in <module>
    binary_img = tifffile.imread('organoid_images/gfp/cells1.tif')
  File "/Users/CosmoCrash/opencvblobs/lib/python3.7/site-packages/tifffile/tifffile.py", line 715, in imread
    with TiffFile(files, **kwargs_file) as tif:
  File "/Users/CosmoCrash/opencvblobs/lib/python3.7/site-packages/tifffile/tifffile.py", line 2238, in __init__
    raise TiffFileError('not a TIFF file')
tifffile.tifffile.TiffFileError: not a TIFF file

您的文件以 \x89P 开头是 PNG 文件,而不是 TIFF,因为它是 PNG 签名,而 TIFF 文件以 II 开头,如果是 Intel 顺序,或 MM 如果是摩托罗拉订单。

如果在 Linux/macOS 上,请尝试 运行:

file cells1.tif

请参阅 Wikipedia 了解 PNG 签名的说明,正如 Warren 所建议的那样。

有关 TIFF header 的说明,请参阅 Wikipedia