【问题标题】:Inverted tiff images and photometric interpretation tag in PIL?PIL中的倒置tiff图像和光度解释标签?
【发布时间】:2020-09-07 16:16:13
【问题描述】:

我正在从头开始创建黑白 TIF 图像,并使用 Python 的图像库在其上绘制文本。在 Windows 7 上使用 Python 2.7、PIL 1.1.7。

要创建每个图像,我使用此代码

def newBinaryImage(w,h):
  return Image.new("1",(w,h),1)

当我在任何 Windows 图像查看器中打开它们时,它们看起来都很好。在我将它们上传到数据库中,然后使用定制的 GUI 查看它们后,它们在 GUI 查看器中看起来很好。但是,当我尝试从 GUI 打印它们时,它们会反转并打印为黑色背景上的白色文本。 (在加载前打印时不会发生这种情况。)

在联系了创建自定义软件的供应商后,他们告诉我们,他们认为问题可能出在 photometricinterpretation 标签上,可以通过使用 Group4 压缩来解决。有没有办法在 PIL 中做到这一点,或者在创建图像时有什么可以/应该改变的吗?

这是我的一张图片上的 Image.DEBUG:

>>>Image.open("1010.tif").show()
tag: ImageWidth (256) - type: short (3) - value: (1200,)
tag: ImageLength (257) - type: short (3) - value: (1600,)
tag: Compression (259) - type: short (3) - value: (1,)
tag: PhotometricInterpretation (262) type: short (3) - value: (1,)
tag: StripOffsets (273) - type: long (4) - value: (98,)
tag: RowsPerStrip (278) - type: short (3) - value: (1600,)
tag: StripByteCounts (279) - type: long (4) - value: (240000,)
*** Summary ***
- compression: raw
- photometric_interpretation: 1
- planar_configuration: 1
- fill_order: 1
- size: (1200,1600)
format key: ('II', 1, 1, 1, (1,), ())
- raw mode: 1
- pil mode: 1

【问题讨论】:

  • 打印机传统上忽略了 1 位图像上的调色板,并简单地假设 0 = 白色和 1 = 黑色。您需要更改图像以匹配,但我认为 PIL 不允许您更改模式 '1' 图像上的调色板。

标签: python python-imaging-library tiff


【解决方案1】:

我最终通过使用 ImageMagick 解决了这个问题。我所做的只是将每个文件从“tif”类型“转换”为“tif”类型,它解决了问题!似乎是 PIL 的压缩问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-30
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多