Just in case you are working with tifffle (.tif) images for a Deep Learning project.
Lately, I was digging my hands into an image processing task - following a tutorial by Dr Sreenivas Bhattiprolu on Digital Image Processing.
In this tutorial, there was a task to read an tif image and convert into readable numbers using skimage.
Code ideally was supposed to be represented in this format:
img = imread("/content/sample_data/Osteosarcoma_01.tif") print(img)
from skimage import io
img = io.imread("/content/sample_data/Osteosarcoma_01.tif")
print(img)
The above code surprisingly returned an error response:ValueError: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package
Solution to this simply is =>
- Downloading the imagecodecs package
Imagecodecs is a Python library that provides block-oriented, in-memory buffer transformation, compression, and decompression functions for use in Tifffile and some other image input/output formats.
python -m pip install -U imagecodecs[all]
Import imread function from the imagecodes package and read the image directly - specifying the path of the .tif image.
python -m pip install -U imagecodecs[all] (#On Terminal) !pip install -U imagecodecs[all] (#On Google Colab) from imagecodecs import imread img = imread("/content/sample_data/Osteosarcoma_01.tif") print(img)
Response =>
[[[ 7 69 61] [11 73 54] [ 8 76 48] ... [13 54 10] [18 59 12] [ 8 70 14]] [[12 77 66] [11 74 60] [ 8 76 55] ... [13 46 9] [21 77 15] [12 85 19]] [[12 86 71] [11 84 66] [ 9 78 60] ... [10 33 9] [10 54 11] [ 5 56 11]] ... [[ 2 34 7] [ 3 27 5] [ 4 28 6] ... [ 1 0 0] [ 1 0 0] [ 0 1 0]] [[ 2 35 7] [ 2 30 6] [ 5 27 5] ... [ 2 3 0] [ 1 2 1] [ 0 0 0]] [[ 3 35 7] [ 3 39 7] [ 4 35 8] ... [ 0 1 0] [ 1 2 1] [ 3 1 0]]]
Goodluck!