问题描述
我正在建立一个计算机视觉项目来检测和处理 GFP 蛋白.我不断收到关于我的文件不是 Tiff 图像和字节错误的错误.我不太明白他们的意思,也没有在网上找到任何关于它的信息.
I am setting up a computer vision project to detect and process GFP proteins. I keep getting errors about my file not being a Tiff Image and a Byte Error. I don't quite understand what they mean and haven't found anything about it online.
我已经确保文件路径正确,并尝试将文件更改为 Tiff 格式.现在在 Finder 上,它说它是 TIFF 图像,但仍然给出错误.
I have already made sure that the file path is correct and have tried changing the file into Tiff Format. Now on Finder, it says that it is a TIFF Image but still gives an error.
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
如果是 Motorola 顺序.
Your file starting \x89P
is a PNG
file, not TIFF
, as that is a PNG signature, whereas TIFF files start II
if in Intel order, or MM
if in Motorola order.
如果在 Linux/macOS 上,请尝试运行:
If on Linux/macOS, try running:
file cells1.tif
请参阅 维基百科,了解 Warren 建议的 PNG 签名说明.
See Wikipedia for description of PNG signature, as suggested by Warren.
请参阅 维基百科了解 TIFF 标头.
See Wikipedia for description of TIFF header.
这篇关于如何解决 TiffFileError: Not a Tiff File and Byte Problem with KeyError: b'\x89P'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!