Reputation: 171
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.
Upvotes: 3
Views: 2687
Reputation: 1624
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
Upvotes: 1
Reputation: 11
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)
Upvotes: 1
Reputation: 21233
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)
Upvotes: 0