tifffile cannot decompress JPEG because JPEG not in TIFF.DECOMPRESSORS

Viewed 5138
import tifffile
f = 'some.tif'
img = tifffile.imread(f)

Gives error:

~/.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

Note: It seems as though I only get the error for larger tif images. Also, the tifffile version is 0.15.1.

UPDATE- After using pip to install imagecodes>=2018.10.22, I'm now getting the following error:

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

On the linux machine on which tifffile can't open the large tif in ~/.conda/envs/cmap_py3/lib/python3.6/site-packages/imagecodecs I see

__init__.py
licencses
__pycache__
imagecodecs.py

On the windows machine on which tifffile can open the large tif in ls C:\\Anaconda2\\envs\\tensorflow35\\lib\\site-packages\\imagecodecs\\ I see

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

I think I had the same struggles as you, @user3731622

Try this code out, as recommended by @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)
Related