Search code examples
pythonimageopencvnumpytiff

OpenCV - Read 16 bit TIFF image in Python (sentinel-1 data)


I'm trying to read a 16 bit TIFF image (26446 x 16688) in Python. Using OpenCV only reads a black image (all the intensities reads 0) by:

    self.img = cv2.imread(self.filename, cv2.IMREAD_UNCHANGED)

Can openCV handle 16 bit or large images (~840mb)? Any workaround?

EDIT: Also cv2.imshow("output", self.img[0:600]) displays a black image.


Solution

  • As suggested by Andrew Paxson a different library can be used. There is a library dedicated exclusively for playing with tiff images.

    Use the following code for the same. Make sure you have tif installed in your system.

    import tifffile as tiff
    import matplotlib.pyplot as plt 
    
    filename = 'Image.tif'
    img = tiff.imread(filename)
    plt.imshow(img)