import tifffile
f = 'some.tif'
img = tifffile.imread(f)
给出错误:
~/.conda/envs/cmap_py3/lib/python3.6/site-packages/tifffile/tifffile.py in imread(files, **kwargs)
443 if isinstance(files, basestring) or hasattr(files, 'seek'):
444 with TiffFile(files, **kwargs_file) as tif:
--> 445 return tif.asarray(**kwargs)
446 else:
447 with TiffSequence(files, **kwargs_seq) as imseq:
~/.conda/envs/cmap_py3/lib/python3.6/site-packages/tifffile/tifffile.py in asarray(self, key, series, out, validate, maxworkers)
1900 typecode, product(series.shape), out=out, native=True)
1901 elif len(pages) == 1:
-> 1902 result = pages[0].asarray(out=out, validate=validate)
1903 else:
1904 result = stack_pages(pages, out=out, maxworkers=maxworkers)
~/.conda/envs/cmap_py3/lib/python3.6/site-packages/tifffile/tifffile.py in asarray(self, out, squeeze, lock, reopen, maxsize, validate)
3376 if self.compression not in TIFF.DECOMPESSORS:
3377 raise ValueError(
-> 3378 'cannot decompress %s' % self.compression.name)
3379 if 'SampleFormat' in tags:
3380 tag = tags['SampleFormat']
ValueError: cannot decompress JPEG
注意:似乎我只收到较大的tif图像的错误。另外,tifffile版本是0.15.1。
更新-
使用pip安装imagecodes>=2018.10.22
后,现在出现以下错误:
img=tifffile.imread(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/somename/.conda/envs/cmap_py3/lib/python3.6/site-packages/tifffile/tifffile.py", line 581, in imread
return tif.asarray(**kwargs)
File "/home/somename/.conda/envs/cmap_py3/lib/python3.6/site-packages/tifffile/tifffile.py", line 2042, in asarray
maxworkers=maxworkers)
File "/home/somename/.conda/envs/cmap_py3/lib/python3.6/site-packages/tifffile/tifffile.py", line 3813, in asarray
strip = decompress(strip)
File "/home/somename/.conda/envs/cmap_py3/lib/python3.6/site-packages/tifffile/tifffile.py", line 3700, in decompress
out)
File "/home/somename/.conda/envs/cmap_py3/lib/python3.6/site-packages/imagecodecs/imagecodecs.py", line 678, in jpeg_decode
'JPEG tables, colorspace, and outcolorspace otions not supported')
NotImplementedError: JPEG tables, colorspace, and outcolorspace otions not supported
在tifffile无法在~/.conda/envs/cmap_py3/lib/python3.6/site-packages/imagecodecs
中打开大tif的Linux机器上,我看到
__init__.py
licencses
__pycache__
imagecodecs.py
在tifffile可以在ls C:\\Anaconda2\\envs\\tensorflow35\\lib\\site-packages\\imagecodecs\\
中打开大tif的Windows计算机上,
__init__.py
licenses
__pycache__
imagecodecs.py
_imagecodecs.cp35-win_amd64.pyd
_jpeg12.cp35-win_amd64.pyd
答案 0 :(得分:0)
@ user3731622,我想和你一样挣扎
按照@cgohlke的建议尝试此代码:
!pip install tifffile
!pip install imagecodecs
import numpy
import tifffile as tiff
img = tiff.imread('/content/gdrive/My Drive/My Driver/imageToDriveExample.tif')
matrix = img[:,:,:]
print(matrix)