问题
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.
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()
Error Message:
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
回答1:
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.
If on Linux/macOS, try running:
file cells1.tif
See Wikipedia for description of PNG signature, as suggested by Warren.
See Wikipedia for description of TIFF header.
来源:https://stackoverflow.com/questions/57315100/how-to-resolve-tifffileerror-not-a-tiff-file-and-byte-problem-with-keyerror-b