6

I used google colab(python) to read a tif file with Tiff file. But it shows:

TiffPage 0: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package.

This is my code:

!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)
0

3 Answers 3

11

You should do below:

pip install imagecodecs

You will be able to use tifffile without error after tart.

2

You could use GDAL, it's installed by default in colab:

import gdal
array = gdal.Open('/content/gdrive/My Drive/My Driver/imageToDriveExample.tif').ReadAsArray()
2

Or use this:

!pip install rasterio 

import rasterio as rio

import numpy as np

with rio.open("file path") as img :

    imgnp= img.read()

    imgmeta=img.meta

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.