python - 在 OpenCV python 中打开未压缩的 TIFF 文件

标签 python opencv tiff

我正在尝试使用 OpenCV 函数 imread 在 python 中打开两个不同的 TIFF 文件

image = cv2.imread(os.path.join(folder, file), -1)

第一个文件打开没有任何问题,但是当我尝试打开第二个文件时,imread 返回“无”。文件之间的唯一区别是第二个文件未压缩。

两个 tiff 图像的属性页: Property page for both tiff images

我还尝试使用 PIL 和 matplotlib 打开第二个文件,但没有成功。

有没有人用 python 成功打开未压缩的 16 位 TIFF 图像?

Here's一个示例文件。如果您想查看图像,请下载并使用 InfranView 打开(Google Drive 不支持查看)

最好的问候,
桑德尔

最佳答案

您的图像不是有效的 TIFF 文件,因为它缺少“光度学解释”,即标签 262。

可以通过libtiff自带的tiffdump查看各种标签

tiffdump Background.tif

输出

Background.tif:
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 2887048 (0x2c0d88) next 0 (0)
ImageWidth (256) SHORT (3) 1<1388>
ImageLength (257) SHORT (3) 1<1040>
BitsPerSample (258) SHORT (3) 1<16>
Compression (259) SHORT (3) 1<1>
StripOffsets (273) LONG (4) 1040<8 2784 5560 8336 11112 13888 16664 19440 22216 24992 27768 30544 33320 36096 38872 41648 44424 47200 49976 52752 55528 58304 61080 63856 ...>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) SHORT (3) 1<1>
StripByteCounts (279) LONG (4) 1040<2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 2776 ...>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<1>

您可以使用libtiff 附带的tiffset 实用程序设置标签,例如:

tiffset -s 262 1 YourUnhappyImage.tif

或者,您可以更正生成它的应用程序。

关于python - 在 OpenCV python 中打开未压缩的 TIFF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48108977/

相关文章:

c++ - OpenCV 错误 : Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat

python - 如何在 Beautifulsoup 中分解 HTML 元素以将它们插入到 MySQL 数据库表中?

Python Beautifulsoup - 单击“加载更多”按钮

python - 使用 OpenCV 检测 python 中的畸形 Blob

Java API 从 tif 源文件中嵌入的剪切路径创建形状

r - 在 R 中将路径/路线图编写为 GeoTiff

c - libtiff 错误 : Old-style JPEG compression support is not configured

python - 3.x 之前的 Python 的正确 SQL 查询

Python-在dict中用作 "dummy value"的最便宜的数据类型是什么

python - 使用 opencv videowriter python 提高视频中的图像质量