[英]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.我正在尝试在 Python 中读取 16 位 TIFF 图像(26446 x 16688)。 Using OpenCV only reads a black image (all the intensities reads 0) by:使用 OpenCV 仅通过以下方式读取黑色图像(所有强度读取为 0):
self.img = cv2.imread(self.filename, cv2.IMREAD_UNCHANGED)
Can openCV handle 16 bit or large images (~840mb)? openCV 可以处理 16 位或大图像 (~840mb) 吗? Any workaround?任何解决方法?
EDIT: Also cv2.imshow("output", self.img[0:600])
displays a black image.编辑: cv2.imshow("output", self.img[0:600])
也显示黑色图像。
Use image libraries specific to raster data (in your case, sentinel-1).使用特定于栅格数据的图像库(在您的情况下为 sentinel-1)。 For example you can use rasterio
for reading and displaying satellite images.例如,您可以使用rasterio
来读取和显示卫星图像。
Example:例子:
import rasterio from rasterio.plot import show img = rasterio.open("image.tif") show(img)
As suggested by Andrew Paxson a different library can be used.正如 Andrew Paxson 所建议的,可以使用不同的库。 There is a library dedicated exclusively for playing with tiff
images.有一个专门用于播放tiff
图像的库。
Use the following code for the same.使用以下代码相同。 Make sure you have tif
installed in your system.确保您的系统中安装了tif
。
import tifffile as tiff import matplotlib.pyplot as plt filename = 'Image.tif' img = tiff.imread(filename) plt.imshow(img)
Yes, OpenCV can read uint16 perfectly fine:是的,OpenCV 可以很好地读取 uint16:
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.默认情况下,像素数必须小于 2^30。 Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS可以使用系统变量 OPENCV_IO_MAX_IMAGE_PIXELS 设置限制
https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56 https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.