【问题标题】:tifffile cannot decompress JPEG because JPEG not in TIFF.DECOMPRESSORStifffile 无法解压缩 JPEG,因为 JPEG 不在 TIFF.DECOMPRESSORS 中
【发布时间】:2018-10-25 21:03:31
【问题描述】:
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

在Windows机器上,tifffile可以打开ls C:\\Anaconda2\\envs\\tensorflow35\\lib\\site-packages\\imagecodecs\\中的大tif,我看到了

__init__.py
licenses
__pycache__
imagecodecs.py
_imagecodecs.cp35-win_amd64.pyd
_jpeg12.cp35-win_amd64.pyd

【问题讨论】:

  • 您的 TIFF 文件是 JPEG 压缩文件,相对较新。你是从哪里弄来的?什么应用?您可以使用magick input.tif -compress lzw output.tif 在命令行中使用 ImageMagick 重新压缩它以使用 LZW 压缩
  • 我不知道图片的原始来源。此外,这是在 linux 机器上。相同版本的 tifffile 似乎能够在我的 windows 机器上打开图像。我试过查看我的 python 库和其他依赖项,但找不到问题。
  • 要读取 JPEG 压缩的 TIFF 文件,请使用 tifffile>=2018.10.18imagecodecs>=2018.10.22
  • 我似乎安装了imagecodecs 20.18.222,但是当我导入它时出现错误.../site-packages/imagecodecs/__init__.py:11: UserWarning: No Module named 'imagecodecs._imagecodecs` The _imagecodecs Cython extension module could not be found. Using a fallback module with limited functionality and performance. `\n\nThe _imagecodecs Cython extension module could not be found.\n' 然后imagecodecs.__version__ 显示为2018.10.21.py
  • 我今天在使用 Cython 和图像编解码器的最新版本时遇到了完全相同的问题。知道如何解决吗?

标签: python-3.x image jpeg tiff compression


【解决方案1】:

我想我和你有同样的挣扎,@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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 2014-02-02
    • 2011-03-29
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    相关资源
    最近更新 更多