Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 543
Damuno Avatar asked Dec 07 '25 11:12

Damuno


2 Answers

Use image libraries specific to raster data (in your case, sentinel-1). For example you can use rasterio for reading and displaying satellite images.

Example:

import rasterio
from rasterio.plot import show

img = rasterio.open("image.tif")

show(img)
like image 177
Anonymous Analyst Avatar answered Dec 10 '25 01:12

Anonymous Analyst


Yes, OpenCV can read uint16 perfectly fine:

img_np = cv2.imread(path, cv2.IMREAD_ANYDEPTH | cv2.IMREAD_UNCHANGED)

Speaking of file size limitation, depends on number of pixels:

By default number of pixels must be less than 2^30. Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS

https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56

like image 44
apatsekin Avatar answered Dec 10 '25 01:12

apatsekin