python - 是否可以在 python 中加载和显示大(8296 x 14740 像素)图像?

标签 python opencv matplotlib tiff

我需要我的 python 脚本以 tiff 格式加载和显示大型(35 MB - 8296 像素 x 14740 像素)图像。 我尝试过使用 openCV:

img = cv2.imread("filename.tif",-1)
cv2.namedWindow('map',cv2.WINDOW_NORMAL)
cv2.imshow('map',img)

我得到了:

OpenCV Error: Assertion failed (size.width>0 && size.height>0)
in cv::imshow, file ..\..\..\..\opencv\modules\highgui\src\window.cpp, line 261

cv2.error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261:
error: (-215) size.width>0 && size.height>0 in function cv::imshow

我也尝试过使用 matplotlib:

img = cv2.imread("filename.tif",-1)
pyplot.imshow(img)
pyplot.show()

我得到了:

TypeError: Image data can not convert to float

如何加载和显示这样的文件?

最佳答案

Matplotlib 提供了一个方便的函数来加载图像:

import matplotlib.pyplot as plt

img = plt.imread('filename.tif')
plt.imshow(img)
plt.show()

关于python - 是否可以在 python 中加载和显示大(8296 x 14740 像素)图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29564905/

相关文章:

python - TensorFlow 2.0 : What is the difference between sparse_categorical_crossentropy and SparseCategoricalCrossentropy?

python - Django collectstatic 不覆盖生产文件

java - 如何使用 OpenCV 的 Watershed Transform 实现过分割?

python - OpenCV 分水岭 + otsu with distanceTransform

python - matplotlib: xaxis dates ValueError: format %y requires year >= 1900 on Windows

python - Matplotlib DatetimeIndex 错误 - 列中没有任何值

python - PCA 仅保留较大的成对距离是什么意思?

python - 使用Python需要将数据从多列转换为单列并重复A列

python - 解密后的明文前面的b在pycrypto中是什么意思?

opencv - 为 haar 级联生成良好的训练数据