在 OpenCV 中打开未压缩的 TIFF 文件 python
Open uncompressed TIFF files in OpenCV python
我正在尝试使用 OpenCV 函数 imread
在 python 中打开两个不同的 TIFF 文件
image = cv2.imread(os.path.join(folder, file), -1)
第一个文件打开没有任何问题,但是当我尝试打开第二个文件时,imread returns 'None'。文件之间的唯一区别是第二个文件未压缩。
属性 两个 tiff 图像的页面:
我也尝试使用 PIL 和 matplotlib 打开第二个文件,但没有成功。
有没有人在 python 中成功打开未压缩的 16 位 TIFF 图像?
Here's 一个示例文件。如果您想查看图像,请下载并使用 InfranView 打开(Google 驱动器不支持查看)
此致,
桑德尔
您的图片不是有效的 TIFF 文件,因为它缺少 "Photometric Interpretation",即标签 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
或者,您可以更正生成它的应用程序。
找到问题的解决方法,其实已经有人回答了here。使用tifffile模块成功打开图片
我正在尝试使用 OpenCV 函数 imread
在 python 中打开两个不同的 TIFF 文件image = cv2.imread(os.path.join(folder, file), -1)
第一个文件打开没有任何问题,但是当我尝试打开第二个文件时,imread returns 'None'。文件之间的唯一区别是第二个文件未压缩。
属性 两个 tiff 图像的页面:
我也尝试使用 PIL 和 matplotlib 打开第二个文件,但没有成功。
有没有人在 python 中成功打开未压缩的 16 位 TIFF 图像?
Here's 一个示例文件。如果您想查看图像,请下载并使用 InfranView 打开(Google 驱动器不支持查看)
此致,
桑德尔
您的图片不是有效的 TIFF 文件,因为它缺少 "Photometric Interpretation",即标签 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
或者,您可以更正生成它的应用程序。
找到问题的解决方法,其实已经有人回答了here。使用tifffile模块成功打开图片