【问题标题】:Open uncompressed TIFF files in OpenCV python在 OpenCV python 中打开未压缩的 TIFF 文件
【发布时间】:2018-01-05 07:23:18
【问题描述】:

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

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

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

两个 tiff 图像的属性页:

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

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

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

最好的问候,
桑德雷

【问题讨论】:

  • 如果您没有得到解决方案,您可以随时在命令行中使用 ImageMagick 来转换任何一种方式,例如convert input.tif -compress lzw output.tifconvert input.tif -compress none output.tif。如果使用 V7 或更新版本,请使用 magick 代替 convert,即 magick input.tif -compress lzw output.tif
  • 你能分享文件Frame_0_369.tif吗?
  • 我已经用示例图片更新了问题。不是同一张图,但问题是一样的

标签: python opencv tiff


【解决方案1】:

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

你可以看到带有tiffdump的各种标签,它带有libtiff

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

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

【讨论】:

    【解决方案2】:

    找到了问题的解决方法,其实已经回答了here。使用 tifffile 模块成功打开图片。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多